我是spring,hibernate集成的新手。
这里有一些代码片段,他们正在抛出javax.el.PropertyNotFoundException。
摘录如下
UsersPrimary.java
package com.iid.users.model;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;
import org.springframework.format.annotation.DateTimeFormat;
@Entity
@Table(name = "Users_Primary")
public class UsersPrimary implements Serializable {
@Id
@Column(name="Email_Address" ,unique=true , nullable=false ,length=30)
private String EmailAddress;
@Column(name="Password", nullable=false ,length=30)
private String Password;
@Column(name="First_Name", nullable=false ,length=30)
private String FirstName;
@Column(name="Last_Name", nullable=false ,length=30)
private String LastName;
@Column(name="Date_Of_Birth", nullable=false)
@DateTimeFormat(pattern="yyyy-MM-dd")
private Date DateOfBirth;
@Column(name="Sex", nullable=false ,length=30)
private String Sex;
@Column(name="RoleName", nullable=false ,length=30)
private String RoleName;
@Column(name="Creation_Time", insertable = false, updatable = false, columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
private Timestamp creationTime;
@Column(name="is_Enabled", nullable=false ,length=30)
private String isEnabled;
@Column(name="Enable_Time", insertable = false , columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
private Timestamp Enable_Time ;
public UsersPrimary() {
// TODO Auto-generated constructor stub
}
public UsersPrimary(String emailAddress, String password, String firstName, String lastName, Date dateOfBirth, String sex, String roleName, Timestamp creationTime, String isEnabled, Timestamp enable_Time) {
super();
EmailAddress = emailAddress;
Password = password;
FirstName = firstName;
LastName = lastName;
DateOfBirth = dateOfBirth;
Sex = sex;
RoleName = roleName;
this.creationTime = creationTime;
this.isEnabled = isEnabled;
Enable_Time = enable_Time;
}
public String getEmailAddress() {
return EmailAddress;
}
public void setEmailAddress(String emailAddress) {
EmailAddress = emailAddress;
}
public String getPassword() {
return Password;
}
public void setPassword(String password) {
Password = password;
}
public String getFirstName() {
return FirstName;
}
public void setFirstName(String firstName) {
FirstName = firstName;
}
public String getLastName() {
return LastName;
}
public void setLastName(String lastName) {
LastName = lastName;
}
public Date getDateOfBirth() {
return DateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
DateOfBirth = dateOfBirth;
}
public String getSex() {
return Sex;
}
public void setSex(String sex) {
Sex = sex;
}
public String getRoleName() {
return RoleName;
}
public void setRoleName(String roleName) {
RoleName = roleName;
}
public Timestamp getCreationTime() {
return creationTime;
}
public void setCreationTime(Timestamp creationTime) {
this.creationTime = creationTime;
}
public String getIsEnabled() {
return isEnabled;
}
public void setIsEnabled(String isEnabled) {
this.isEnabled = isEnabled;
}
public Timestamp getEnable_Time() {
return Enable_Time;
}
public void setEnable_Time(Timestamp enable_Time) {
Enable_Time = enable_Time;
}
}
下面是控制器类
的控制器方法的片段SearchController.java
private UsersPrimaryService ups ;
@RequestMapping(value = "/search", method = RequestMethod.POST)
@ResponseBody
public ModelAndView search(@RequestParam(value="SearchField")String SearchField,HttpSession sessionObj, HttpServletRequest req) {
ModelAndView model = new ModelAndView();
System.out.println(SearchField);
sessionObj.setAttribute("searchResultList" , ups.searchUsersPrimaryList(SearchField));
model.setViewName("/WEB-INF/jsp/Search/searchResult");
return model;
}
及以下是searchResult.jsp的片段
<c:forEach items="${searchResultList}" var="UsersPrimary">
<a href="#"> <c:out value="${UsersPrimary.EmailAddress}"></c:out> <c:out value="${UsersPrimary.FirstName}"></c:out> <c:out value="${UsersPrimary.LastName}"></c:out> </a>
</c:forEach>
每次我运行代码gettting
javax.el.PropertyNotFoundException: Property 'EmailAddress' not found on type com.iid.users.model.UsersPrimary
不知道为什么?我正在使用spring 4.1.1和hibernate 4.3.6。 。
是某种错误或我的片段错了吗?
答案 0 :(得分:2)
EmailAddress
字段的getter是否为getEmailAddress()
?这可能是大写/小写字段名称的问题。通常,字段名称应以小写字母开头(因此emailAddress
而不是EmailAddress
),它是全局接受的约定,许多框架在使用反射时依赖于它。
虽然它可能是您的主要重构,但您应将字段更改为lowerCamelCase,并在您的特定情况下使用名为getEmailAddress()
的getter将其更改。
作为快速解决方法,请尝试将表达式更改为<c:out value="${UsersPrimary.getEmailAddress()}"></c:out>
。