EL1007E: Property or field 'username' cannot be found on null


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM