HTTP状态500 - javax.el.PropertyNotFoundException

时间:2016-02-17 14:40:36

标签: java mysql hibernate spring-mvc

我试图做简单的CRUD。我收到此错误 - javax.el.PropertyNotFoundException:Property' isAdmin'找不到类型com.kaasbetrayer.entity.User。 并且我不知道如何解决它。

package com.kaasbetrayer.entity;

import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.Type;
import org.hibernate.type.descriptor.sql.TinyIntTypeDescriptor;
@Entity
@Table(name = "user")
public class User implements Serializable{

    private static final long serialVersionUID = -6254657371433674903L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    @Column
    private String name;

    @Column
    private int age;

    @Column
    @Type(type = "org.hibernate.type.NumericBooleanType")
    private boolean isAdmin;

    @Column
    private Timestamp createdDate;

    public User(){
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public boolean isAdmin() {
        return isAdmin;
    }

    public void setAdmin(boolean isAdmin) {
        this.isAdmin = isAdmin;
    }

    public Timestamp getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Timestamp createdDate) {
        this.createdDate = createdDate;
    }

    @Override
    public String toString() {
        return "User {id=" + id + 
                ", name=" + name + 
                ", age=" + age + 
                ", isAdmin=" + isAdmin + 
                ", createdDate="+ createdDate + "}";
    }       
}

堆栈追踪:

org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: Property 'isAdmin' not found on type com.kaasbetrayer.entity.User
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:555)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

根本原因

javax.el.PropertyNotFoundException: Property 'isAdmin' not found on type com.kaasbetrayer.entity.User
    javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:268)
    javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:221)
    javax.el.BeanELResolver.property(BeanELResolver.java:355)
    javax.el.BeanELResolver.getValue(BeanELResolver.java:95)
    org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110)
    org.apache.el.parser.AstValue.getValue(AstValue.java:169)
    org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
    org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:943)
    org.apache.jsp.WEB_002dINF.pages.userList_jsp._jspx_meth_c_005fout_005f3(userList_jsp.java:400)
    org.apache.jsp.WEB_002dINF.pages.userList_jsp._jspx_meth_c_005fforEach_005f0(userList_jsp.java:299)
    org.apache.jsp.WEB_002dINF.pages.userList_jsp._jspx_meth_c_005fif_005f1(userList_jsp.java:249)
    org.apache.jsp.WEB_002dINF.pages.userList_jsp._jspService(userList_jsp.java:155)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

SQL:

 create table User (
 id bigint not null auto_increment,
 name varchar(255),
 age integer,
 isAdmin boolean,
 createdDate timestamp,
 primary key (id)
 )

2 个答案:

答案 0 :(得分:3)

如果您坚持命名属性isAdmin,则应将get / setters命名为boolean isIsAdmin()setIsAdmin(boolean isAdmin)

答案 1 :(得分:0)

据我所知,属性isAdmin的getter和setter看起来应该像getIsAdminsetIsAdmin而不是isAdminsetAdmin。 getter和Setter通常应该看起来像get/set,后跟属性名称,并带有Caps中的第一个字母。