session中取對象的屬性時,如果對象本身為空,就會報錯
解決辦法:
原來的代碼:
<span th:text="${session.user.username}"></span>
更改后代碼:
<span th:text="${session.user?.username}"></span>
為什么加個?就可以解決
因為這是一個thymeleaf判斷對象是否為空的方法。thymeleaf中顯示某對象使用${username},但如果username為null,thymeleaf就會報錯
轉載自:https://blog.csdn.net/weixin_41699562/article/details/103208848