Thymeleaf:有条件的:价值

时间:2017-05-12 11:01:23

标签: thymeleaf

问题:
$ {map}可以为null。

<input type="text" th:value="${map.name}" />

我需要什么:
如果name不为null,则th:value = name,否则th:value =“”

 <input type="text" th:value="${map.name != null ? map.name : ''}" />

但我的上述代码无效

1 个答案:

答案 0 :(得分:2)

解决方案:

<input th:value="${map !=null}? ${map.name} : ''" />

或更好(与Elvis运营商合作):

<input type="text" th:value="${map?.name}"
相关问题