我有以下两个有一对多映射的类。学生可以选择多个科目。
@Entity
@Table ( name = "studentinfo" )
public class student {
@Id
@GeneratedValue ( strategy = GenerationType.IDENTITY )
@Column ( name = "stud_id" )
private int studId;
@NotEmpty
@Column ( name = "stud_name" )
private String studname;
@NotEmpty
@Column ( name = "stud_age" )
private int studage;
@OneToMany (cascade = CascadeType.ALL)
@JoinColumn ( name = "stud_sub_id" )
private List<subject> subject;
//getters and setters
主题模型类
@Entity
@Table ( name = "subject" )
public class subject {
@Id
@GeneratedValue ( strategy = GenerationType.IDENTITY )
@Column ( name = "Sub_id" )
private int subId;
@NotEmpty
@Column ( name = "Subj_name" )
private String subjname;
//getters and setters
我如何使用表格:选择标签以显示主题列表,以便我可以为学生选择多个主题,同时在编辑特定学生详细信息时,我需要为他显示所选主题。这是我目前的jsp代码。
<form:form commandName="studentdetails" action="${pageContext.request.contextPath}/stud/studentadded" method="post">
<form:hidden path="studId"/>
<table>
<tr>
<td><label for="studname">Name: </label> </td>
<td><form:input path="studname" id="name"/></td>
<td><form:errors path="studname" cssStyle="color:#ff0000"></form:errors></td>
</tr>
<tr>
<td><label for="studage">Age: </label> </td>
<td><form:input path="studage" id="age"/></td>
<td><form:errors path="studage" cssStyle="color:#ff0000"></form:errors></td>
</tr>
<tr>
<td><label for="subject.subjname">Opting Subject: </label> </td>
<td>
<form:select path="subject.subjname">
<form:option value="" label="select"></form:option>
<form:options items="${subjects}"/>
</form:select>
</td>
<td><form:errors path="subject.subjname" cssStyle="color:#ff0000"></form:errors></td>
</tr>
<tr>
<td colspan="3">
<input type="Submit" value="Add"/>
</td>
</tr>
</table>
</form:form>
我的表格支持对象属于学生班级。这里的项目=&#34; $ {subject}&#34;包含我从控制器传递的List<String>
中的主题列表。对于path =&#34; subject.subjname&#34;它显示以下错误;
org.springframework.beans.NotReadablePropertyException: Invalid property 'subject.subjname' of bean class [com.model.studentinfo]: Bean property 'subject.subjname' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
但我有适当的吸气剂和setter方法。如果我使用path =&#34; subject&#34;,我在提交时收到以下错误。
400 The request sent by the client was syntactically incorrect
但我没有使用任何日期属性。我如何制作表格:选择加入和编辑学生的工作。请帮帮我。
答案 0 :(得分:0)
您必须在表单后备对象“studentdetails”中创建一个String of input inputSubjects字段,并在路径中使用以下内容:
<form:form modelAttribute="studentdetails" action="${pageContext.request.contextPath}/stud/studentadded" method="post">
<form:select multiple="true" path="inputSubjects">
<form:option value="" label="select"></form:option>
<form:options items="${subjects}"/>
</form:select>