If-Else in a th:each statement in Thymeleaf

后端 未结 2 2000
灰色年华
灰色年华 2021-02-03 15:16

What I want is an if-else in a th:each statement in Thymeleaf.

If currentSkill != null, then show table with content, else \'You don\'t have any skills\'

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-03 16:13

    You don't have any skills

    If currentSkills is a list, you can use the #lists utility like so (which is more correct than the above code since it also takes into account the possibility where the object is not null but is empty):

     
    You don't have any skills

    You could do the same if currentSkills is an array by just replacing #lists with #arrays.

    Note that in both cases isEmpty() returns true whether the object is null or has zero items.

提交回复
热议问题