Using Thymeleaf when the value is null

2019-01-21 12:49发布

I have some values in my database which can be null if they have not already been entered.

But when I use Thymeleaf in my html, it gives an error when parsing null values.

Is there any way to handle this?

8条回答
再贱就再见
2楼-- · 2019-01-21 13:16

I use

<div th:text ="${variable != null} ? (${variable != ''} ? ${variable} : 'empty string message') : 'null message' "></div>
查看更多
女痞
3楼-- · 2019-01-21 13:22
   <p data-th-text ="${#strings.defaultString(yourNullable,'defaultValueIfYourValueIsNull')}"></p>
查看更多
登录 后发表回答