<label class="label">授课教师</label>
        <p class="content" id="teacher">
            <span th:if="${course!=null}"
                  th:each="i:${course.teachers}"
                  th:text="${i}+'<br>'">
            </span>
        </p>如果后台传过来的是一个空对象怎么办啊,这样会报错,一直找不到解决方法。
Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "course.teachers" (template: "index" - line 126, col 19)
at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393) ~[attoparser-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.attoparser.MarkupParser.parse(MarkupParser.java:257) ~[attoparser-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.thymeleaf.templateparser.up.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
... 52 common frames omitted

解决方案 »

  1.   

    <span th:if="${course}"
                      th:each="i:${course.teachers}"
                      th:text="${i}+'<br>'">
                </span>
    空就是false
      

  2.   

    想办法不要让course为空.
    比如: 写入0或1
      

  3.   

    再加一个判断呗:<span th:if="${course!=null and course.teachers!=null}"
                      th:each="i:${course.teachers}"
                      th:text="${i}+'<br>'">
                </span>
      

  4.   

    <span th:each="i:${course?.teachers}"
                      th:text="${i}+'<br>'">
                </span>
    给需要判断的对象加一个问号就可以!