这是我的实体
@Entity
public class User implements java.io.Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
private String mobNum;
private String email;
String gender;
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
LocalDate bdate;
public LocalDate getDate() {
return bdate;
}
public void setDate(LocalDate bdate) {
this.bdate = bdate;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public User() {
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getMobNum() {
return this.mobNum;
}
public void setMobNum(String mobNum) {
this.mobNum = mobNum;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
}
这是我的Spring-Form
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form:form action="add_student_data.htm" method="POST" commandName="user">
<table>
<tr>
<td><form:label path="name">Name</form:label></td>
<td><form:input path="name"/></td>
<td><font color="red" /><form:errors path="name" cssClass="error" /></td>
</tr>
<tr>
<td><form:label path="bdate" >Date Of Birth</form:label></td>
<td><form:input path="bdate"/></td>
<td><font color="red" /><form:errors path="bdate" cssClass="bdate" /></td>
</tr>
<tr>
<td><form:label path="gender" >Gender</form:label></td>
<td><form:radiobutton path="gender" value="M" label="M" />
<form:radiobutton path="gender" value="F" label="F" /></td>
</tr>
<tr>
<td><form:label path="mobNum">Mob Num</form:label></td>
<td><form:input path="mobNum"/></td>
<td><font color="red" /><form:errors path="mobNum" ccssClass="error"/></td>
</tr>
<tr>
<td><form:label path="email">Email</form:label></td>
<td><form:input path="email"/></td>
<td><font color="red" /><form:errors path="email" cssClass="error" /></td>
</tr>
</table>
<input type="submit" value="submit">
</form:form>
</body>
</html>
当我想打开这个fom错误时,就像
一样&#34; org.apache.jasper.JasperException:org.springframework.beans.NotReadablePropertyException:无效的属性&#39; dateOfBirth&#39; bean类[com.domain.User]:Bean属性&#39; dateOfBirth&#39;不可读或getter方法无效:getter的返回类型是否与setter的参数类型匹配?&#34;
我在用户实体中使用joda.org.time.LocalDate。问题的原因是什么?
答案 0 :(得分:0)
JSP中的getter / setter方法名称和变量名称不匹配,请更改以下方法:
public LocalDate getDate() {
return bdate;
}
public void setDate(LocalDate bdate) {
this.bdate = bdate;
}
到
public LocalDate getBdate() {
return bdate;
}
public void setBdate(LocalDate bdate) {
this.bdate = bdate;
}