SpringBoot + Thymeleaf调用接口报错EL1007E: Property or field ‘xxx‘ canno be found on null
·
关键报错信息如下:
2020-08-09 18:35:20.334 ERROR 1936 --- [http-nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/admin/blogs.html]")] with root cause
org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'totalPages' cannot be found on null
编译器认为totalPages取得的值为空,而实际情况是有值的,它说为空,可能是出现了为空的情况,为空的情况传入参数就出现了报错。
所以在参数传递前进行判断,以下是报错前代码:
<div class="ui mini pagination menu" th:if="${page.totalPages}>1">
<a οnclick="page(this)" th:attr =" data-page = ${page.number}-1)}" class=" item" th:unless="${page.first}">上一页</a>
<a οnclick="page(this)" th:attr = " data-page = ${page.number}+1)}" class=" item" th:unless="${page.last}">下一页</a>
</div>
修改后
<th:block th:if="${page != null}" >
<div class="ui mini pagination menu" th:if="${page.totalPages}>1">
<a οnclick="page(this)" th:attr =" data-page = ${page.number}-1)}" class=" item" th:unless="${page.first}">上一页</a>
<a οnclick="page(this)" th:attr = " data-page = ${page.number}+1)}" class=" item" th:unless="${page.last}">下一页</a>
</div>
</th:block>
随后可以成功运行。
更多推荐
所有评论(0)