org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field ‘getMessage’ cannot be found on null
SpringBoot整合Thymeleaf报错
原因:在null上调用了方法。
错误,第一次的时候没有异常, 所以th:if="${not #strings.isEmpty(exception.getMessage())
在调用getMessage()
方法的时候就会出现方法在null放被调用的异常,修改成th:if="${not #strings.isEmpty(exception)
直接判断exception
是不是空就行了,不用调用它的方法
<!--错误,第一次的时候没有异常,
所以th:if="${not #strings.isEmpty(exception.getMessage())在调用getMessage()方法的时候
就会出现方法在null放被调用的异常,
修改成th:if="${not #strings.isEmpty(exception)
直接判断exception是不是空就行了,不用调用它的方法-->
<!-- <span th:text="${(exception.getMessage())}" th:if="${not #strings.isEmpty(exception.getMessage())}" style="color: red"></span>-->
<!-- <span th:text="${(exception)}" th:if="${not #strings.isEmpty(exception)}" style="color: red"></span>-->
<span th:text="${(exception.getMessage())}" th:if="${not #strings.isEmpty(exception)}" style="color: red"></span>