值为空时使用Thymeleaf [英] Using Thymeleaf when the value is null

查看:423
本文介绍了值为空时使用Thymeleaf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有一些值,如果尚未输入,则可以为null.

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

但是当我在HTML中使用Thymeleaf时,解析空值时会出现错误.

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

有什么办法可以解决这个问题?

Is there any way to handle this?

推荐答案

最短的方法是使用'?'操作员.如果您具有带有嵌入式地址实体的用户实体,以便访问地址实体的字段并在地址不为null的情况下进行打印,则此处将为空列:

The shortest way is using '?' operator. If you have User entity with embedded Address entity in order to access fields of Address entity and print them if address is not null, otherwise here will be an empty column:

<td th:text="${user?.address?.city}"></td>

这篇关于值为空时使用Thymeleaf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆