Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何正确放置列表<;对象>;在Spring窗体中:选择窗体:选项?_Java_Jsp_Spring Mvc_Jstl_Spring Form - Fatal编程技术网

Java 如何正确放置列表<;对象>;在Spring窗体中:选择窗体:选项?

Java 如何正确放置列表<;对象>;在Spring窗体中:选择窗体:选项?,java,jsp,spring-mvc,jstl,spring-form,Java,Jsp,Spring Mvc,Jstl,Spring Form,我想在表单中列出一个对象规程列表:选择所选规程值并将其链接到提交时年级对象的路径:“规程” 我现在就是这样做的,将grade.dictionary.id链接到dictionary.id。它正在工作,我在服务器上使用了debug,并看到了grade对象中的规程是如何获得规程对象的。但我想知道是否有一种“书外之道”,而不仅仅是我的即兴创作 addGrade.jsp文件: <form:form commandName="grade"> <table> &

我想在表单中列出一个对象规程列表:选择所选规程值并将其链接到提交时年级对象的路径:“规程”

我现在就是这样做的,将grade.dictionary.id链接到dictionary.id。它正在工作,我在服务器上使用了debug,并看到了grade对象中的规程是如何获得规程对象的。但我想知道是否有一种“书外之道”,而不仅仅是我的即兴创作

addGrade.jsp文件:

<form:form commandName="grade">
    <table>
        <tr>
            <th>Value = </th>
            <td><form:input path="value"/></td>
            <td><form:errors path="value"/></td>
        </tr>
        <tr>
            <th>Select discipline: </th>
            <td colspan = "2">
                <form:select path="discipline.id">
                    <c:forEach items="${disciplines}" var="d">
                        <option value="${d.id}">${d.name}</option>"
                    </c:forEach>
                </form:select>
            </td>
            <td><form:errors path="discipline"/></td>
        </tr>
        <tr>
            <td colspan="2"><input type="submit" value="Submit"/></td>
        </tr>
    </table>
</form:form>
我知道我应该使用:

<form:select path="discipline">
    <form:options items="${disciplines}"/>
</form:select>
@Entity
public class Discipline {
@Id
@GeneratedValue
private Long id;
@NotNull
private String name;
@OneToMany(mappedBy="discipline", cascade=CascadeType.ALL,fetch=FetchType.LAZY,orphanRemoval=true)
private List<Grade> grades = new ArrayList<Grade>();
// getters and setters ..... 
}
@Entity
public class Grade {
@Id
@GeneratedValue
private Long id;
@Range(min=1, max=10)
@NotNull
private int value;
@ManyToOne
private Student student;
@ManyToOne
private Discipline discipline;
// getters and setters .... 
}
<form:select path="discipline">
    <form:options items="${disciplines}"/>
</form:select>
List<Discipline> disciplines = disciplineService.findAll();
Map<Discipline,String> disciplinesHashMap = new LinkedHashMap<Discipline,String>();
for (Discipline temp:disciplines){
    disciplinesHashMap.put(temp, temp.getName());           
}
model.addAttribute("disciplines",disciplinesHashMap);
java.lang.NullPointerException
com.app.service.GradeServiceImpl.findByStudentAndDiscipline(GradeServiceImpl.java:31)