Thymeleaf之SpelEvaluationException: EL1007E: Property or field '***' canno be found on null

modelAndView.addObject("loginUser", user);

loginUser里面有username属性

当我们想获取username时,需要加上if判断,即判断loginUser不为null
<th:block th:if="${loginUser!= null}">

  <p th:text="${loginUser.username}"></p>

</th:block>

posted @ 2020-06-19 18:47  大浩  阅读(2553)  评论(0)    收藏  举报