javax.el.PropertyNotFoundException : Property 'EmailAddress' not found on type com. iid.users.model.UsersPrimary

标签 java spring hibernate jsp

我是 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;
    }


}

下面是 Controller 类的 Controller 方法的片段

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的 setter/getter 名为 getEmailAddress() 的字段?这可能是大/小写字段名称的问题。通常,字段名称应以小写字母开头(因此 emailAddress 而不是 EmailAddress ),这是全局公认的约定,许多框架在使用反射时都依赖于它。

虽然这对您来说可能是一次重大重构,但您应该将字段更改为 lowerCamelCase在您的特定情况下, setter/getter 名为 getEmailAddress()它应该可以工作。

作为快速解决方法,请尝试将表达式更改为 <c:out value="${UsersPrimary.getEmailAddress()}"></c:out> .

关于javax.el.PropertyNotFoundException : Property 'EmailAddress' not found on type com. iid.users.model.UsersPrimary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29075213/

相关文章:

java - 当子实体与父实体之间存在一对一的 JPA 关系时,是否可以将子实体与父实体一起保留?

hibernate - HQL:将 "insert into ... select"与固定参数值结合起来

java - 在 Javassist 中修改行号

java - spring中的ContextLoad错误

java - 将 float 组和浮点值复制到字节缓冲区 - Java

java - Spring Data @CreatedDate 注释对我不起作用

java - 如何为@Valid 指定验证组?

hibernate - 如何在JPQL中选择多个count()选择的总和

java - Hibernate 查询以选择 Datetime 列的时间范围内的行

java - 无法解析某些属性的占位符