在文本中的百万美元串联覆盖了以前的值

问题描述 投票:0回答:1

我想连接两个字符串变量。要求非常简单取决于条件我只需要连接一个静态字符串“Out of office”。然而,当它被渲染时,只显示“不在办公室”而不是先前的变量值,如名字和姓氏。任何的想法?

<option th:text="${assignee.getUserProfile().getFirstName() + ' ' + assignee.getUserProfile().getLastName() + assignee.getUserProfile().getOutOfOfficeApproval() != null? '(Out of office)':''}"/>
spring-boot thymeleaf
1个回答
0
投票

像这样:

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

您可以使用th:with,inlining和javabean格式来改进格式。像这样的东西之一:

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

hr(哦/ Thimeleaf)

<option th:with="profile=${assignee.userProfile}">
    [[${profile.firstName + ' ' + profile.lastName}]]
    [[${profile.outOfOfficeApproval != null? '(Out of office)' : ''}]]
</option>
© www.soinside.com 2019 - 2024. All rights reserved.