Property or field 'username' cannot be found on null
生活随笔
收集整理的這篇文章主要介紹了
Property or field 'username' cannot be found on null
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
報錯原因:
username不能為空
解決辦法:
原來的代碼:
<span th:text="${session.user.username}"></span>更改后代碼:
<span th:text="${session.user?.username}"></span>為什么加個?就可以解決
因為這是一個thymeleaf判斷對象是否為空的方法。thymeleaf中顯示某對象使用${username},但如果username為null,thymeleaf就會報錯。
總結
以上是生活随笔為你收集整理的Property or field 'username' cannot be found on null的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: inner join和left join
- 下一篇: “http://127.0.0.1:88