2017-05-12 2 views
0

Problem:
$ {map} kann null sein.Thymoleaf: Bedingt th: Wert

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

Was ich brauche:
Wenn der Name nicht null ist, th: Wert = name sonst th: value = ""

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

Aber mein obiger Code ist nicht gültig

Antwort

1

Lösung:

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

oder besser (mit Elvis Operator):

<input type="text" th:value="${map?.name}" 
Verwandte Themen