我是新来的,冬眠整合。
这是一些代码片段,它们引发了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>
每当我运行代码获取时
javax.el.PropertyNotFoundException: Property 'EmailAddress' not found on type com.iid.users.model.UsersPrimary
不知道为什么?我正在使用Spring 4.1.1和Hibernate 4.3.6。 。
是某种错误还是我的代码片段错了?
最佳答案
EmailAddress
字段的吸气剂是否称为getEmailAddress()
?大写/小写字段名称可能是一个问题。通常,字段名称应以小写字母开头(因此emailAddress
而不是EmailAddress
),这是全球公认的约定,在使用反射时,很多框架都依赖于它。
尽管这可能对您来说是一个重要的重构,但是您应该将字段更改为lowerCamelCase,在特殊情况下,使用名为getEmailAddress()
的getter可以正常工作。
作为一种快速的解决方法,尝试将表达式更改为<c:out value="${UsersPrimary.getEmailAddress()}"></c:out>
。