Caused by: org.springframework.beans.NotReadablePropertyException

异常详情:

Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'dayNew' of bean class [com.zttech.demo.cms.entity.CmsConfigAttr]: Bean property 'dayNew' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
    at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:619) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:610) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:99) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.java:229) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.web.servlet.support.BindStatus.(BindStatus.java:120) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:168) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:188) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:154) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:141) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:132) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:116) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:422) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.apache.jsp.WEB_002dINF.views.demo.cms.global.otherHome_jsp._jspx_meth_form_005finput_005f0(otherHome_jsp.java:506) ~[?:?]
    at org.apache.jsp.WEB_002dINF.views.demo.cms.global.otherHome_jsp._jspx_meth_form_005fform_005f0(otherHome_jsp.java:373) ~[?:?]
    at org.apache.jsp.WEB_002dINF.views.demo.cms.global.otherHome_jsp._jspService(otherHome_jsp.java:165) ~[?:?]
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) ~[jasper.jar:7.0.78]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) ~[servlet-api.jar:?]
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439) ~[jasper.jar:7.0.78]
    ... 84 more

原因:jsp中的标签中哟一个属性path,它里面的字符串内容要和modelAttribute中对应的类的getter和setter方法后面跟的属性名称一致。

拿这个错误举例,

"inputForm" modelAttribute="cmsConfigAttr" action="${ctx}/cms/global/otherEdit.jhtml" method="post" class="form-horizontal">

标签的modelAttribute中我设置了cmsConfigAttr。这是一个CmsConfigAttr类的对象,它里面有个DAYNEW属性。

public static final String DAYNEW = "day";

这是一个static final 的字符串,按照标准来说是要全部大写的。于是在自动生成getter和setter方法的时候就会变成getDaynew()setDaynew.

所以在使用的时候,path里面就不能写dayNew,而是要写daynew。就是用getXxxxx(),再把第一个字母小写。

boolean类型的isXxxx(),同理。

你可能感兴趣的:(java)