错误描述
问题的关键在于Idea和Eclipse自动生成的get和set方法不一样
javax.el.PropertyNotFoundException: Property 'isMemberCourse' not readable on type com.test.ServiceCategoryDTO
at javax.el.BeanELResolver$BeanProperty.read(BeanELResolver.java:305)
at javax.el.BeanELResolver$BeanProperty.access$000(BeanELResolver.java:253)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:1026)
at org.apache.jsp.WEB_002dINF.jsp.studyCenter.studyCenter_jsp._jspx_meth_c_005fforEach_005f4(studyCenter_jsp.java:4247)
at org.apache.jsp.WEB_002dINF.jsp.studyCenter.studyCenter_jsp._jspx_meth_c_005fif_005f64(studyCenter_jsp.java:4197)
at org.apache.jsp.WEB_002dINF.jsp.studyCenter.studyCenter_jsp._jspx_meth_c_005fif_005f63(studyCenter_jsp.java:4148)
at org.apache.jsp.WEB_002dINF.jsp.studyCenter.studyCenter_jsp._jspService(studyCenter_jsp.java:1943)
private boolean isMemberCourse = Boolean.FALSE;
public boolean isMemberCourse() {
return isMemberCourse;
}
public void setIsMemberCourse(boolean isMemberCourse) {
this.isMemberCourse = isMemberCourse;
}
问题分析
明明类中有个属性,怎么会提示这个属性没有呢?就是因为EL取值是根据Get方法来取值的。并没有isMemberCourse的get方法。原因就是get方法不对!
最后将Get和Set方法更改就好了
public boolean getIsMemberCourse() {
return isMemberCourse;
}
public void setIsMemberCourse(boolean isMemberCourse) {
this.isMemberCourse = isMemberCourse;
}
类似的问题还有FastJson这个工具包转Json的时候也会根据get/set方法来生成,也会造成属性和json中的属性不一样的情况。
这个问题应该是普遍的,很多地方都应该会出现类似的问题。