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

ession中取对象的属性时,如果对象本身为空,就会报错

解决办法:
原来的代码:

<span th:text="${session.user.username}"></span>

更改后:

<span th:text="${session.user?.username}"></span>

为什么加个?就可以解决
因为这是一个thymeleaf判断对象是否为空的方法。thymeleaf中显示某对象使用${username},但如果username为null,thymeleaf就会报错

posted @ 2021-11-15 15:30  Kaspar_Choo  阅读(3620)  评论(0编辑  收藏  举报