【问题标题】:javax.el.PropertyNotFoundException: The class 'com.springapp.mvc.Class' does not have the property 'Courses' [duplicate]javax.el.PropertyNotFoundException:类“com.springapp.mvc.Class”没有属性“课程”[重复]
【发布时间】:2015-07-08 16:24:12
【问题描述】:

这是我的模型:

public class Class {
    @ManyToMany(etc etc)
    @JoinTable(etc etc)
    public List<Course> Courses;

这是我的看法:

<c:forEach items="${classes}" var="class">
<tr>
    <td>${class.className}</td>
    <td>
    <c:forEach items="${courses}" var="course">
        <input type="checkbox"
            <c:if test="${class.Courses.contains(course)}"> checked</c:if>>
        ${course.courseName}
    </c:forEach>
    </td>
</tr>
</c:forEach>

视图只产生这个 500 错误:

javax.el.PropertyNotFoundException:“com.springapp.mvc.Class”类没有“课程”属性。

【问题讨论】:

    标签: java jstl el propertynotfoundexception


    【解决方案1】:

    EL 不寻找属性,而是寻找 getter:

    public class AnyClass {
    
      private String aProperty;
    
      private String getAGetter() {
        // ...
      }
    
    }
    

    ${anyClass.aProperty} 将失败,${anyClass.aGetter} 将成功。

    要将 getter 名称转换为 EL 表达式,删除“get”(或“is”)前缀,并将第一个 char 小写。

    在你的情况下,我猜你的吸气剂名字是getCourses,它给出了courses。所以你必须使用${class.courses}


    请注意,您没有关注Java naming conventions

    【讨论】:

      猜你喜欢
      • 2011-07-14
      • 2011-11-11
      • 1970-01-01
      • 2012-08-14
      • 1970-01-01
      • 1970-01-01
      • 2015-03-02
      • 2017-07-28
      • 2015-07-29
      相关资源
      最近更新 更多