th:text中的胸腺叶串联将覆盖先前的值

时间:2019-03-07 08:00:47

标签: spring-boot thymeleaf

我想连接两个字符串变量。要求非常简单,取决于条件,我只需要串联一个静态字符串“ Out of office”。但是,当渲染它时,仅显示“不在办公室”,而不显示以前的变量值,例如名字和姓氏。有什么主意吗?

<option th:text="${assignee.getUserProfile().getFirstName() + ' ' + assignee.getUserProfile().getLastName() + assignee.getUserProfile().getOutOfOfficeApproval() != null? '(Out of office)':''}"/>

1 个答案:

答案 0 :(得分:0)

赞:

<option th:text="${assignee.getUserProfile().getFirstName() + ' ' + assignee.getUserProfile().getLastName() + (assignee.getUserProfile().getOutOfOfficeApproval() != null? '(Out of office)':'')}"/>

您还可以使用th:with,内联和javabean格式来改进格式。类似于其中之一:

<option th:with="profile=${assignee.userProfile}" th:text="${profile.firstName + ' ' + profile.lastName + (profile.outOfOfficeApproval != null? ' (Out of office)' : '')}">

或(带有Thymeleaf 3)

<option th:with="profile=${assignee.userProfile}">
    [[${profile.firstName + ' ' + profile.lastName}]]
    [[${profile.outOfOfficeApproval != null? '(Out of office)' : ''}]]
</option>