There is an object called "Man" and an object called "Course" with the attitude of many to many. The union object is called "PersonCourse".
@Entity @Table(name="person_course") public class PersonCourse implements Serializable { @Id @ManyToOne @JoinColumn(name="course_ID") private Course course; @Id @ManyToOne @JoinColumn(name="person_ID") private Person person;
I have the following form with which I must save information in "PersonCourse":
<form:form method="post" action="addpersoncourse.html" commandName="personcourse"> <form:label path="person"><spring:message code="label.person"/></form:label> <form:select path="person"> <c:forEach items="${personList}" var="person"> <form:option value="${person.id}">${person.firstName} ${person.lastName}</form:option> </c:forEach> </form:select> <form:label path="course"><spring:message code="label.course"/></form:label> <form:select path="course"> <c:forEach items="${courseList}" var="course"> <form:option value="${course.id}">${course.course}</form:option> </c:forEach> </form:select> <input type="submit" value="<spring:message code="label.addpersoncourse"/>"/> </form:form>
In the controller, I try to read the information in the following way:
@RequestMapping(value = "/addpersoncourse", method = RequestMethod.POST) public String addpersoncourse(@ModelAttribute("personcourse") PersonCourse personCourse, BindingResult result) {
But for some reason personcourse.person and personcourse.course are null. What could be wrong?
source share