gpt4 book ai didi

string - Thymeleaf 为每个字符串替换一个子字符串

转载 作者:行者123 更新时间:2023-12-01 15:43:29 25 4
gpt4 key购买 nike

我有一个对象列表。每个对象都有一个带有特定前缀的名称。现在我想用空字符串替换此前缀。

我的代码:

Controller :

@Secured("ROLE_ADMIN")
@RequestMapping(value = "/admin/userManagement", method = RequestMethod.GET)
public String showUserManagement(Model model) {
model.addAttribute("userList", userDelegate.getAllUserForClient(getCompanyAuthority().getName()));
model.addAttribute("companyName", getCompanyAuthority().getName());
return "admin/user_management";
}

我的 html 片段:

<table class="table table-striped table-hover">
<thead>
<tr>
<th>ID</th>
<th>E-mail</th>
<th th:text="#{adminArea.userManagementReport}">Reports</th>
<th th:text="#{adminArea.userManagementRole}"></th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<tr th:each="user,itrStat : ${userList}">
<td th:text="${itrStat.index}"></td>
<td th:text="${user.username}"></td>
<td>
<small th:each="report : ${user.reports}"
th:utext="${#strings.replace(report.name,companyName + '_','')} : ${companyName}"></small>
<br th:each="report : ${user.reports}"></br></td>
</tr>
</tbody>
</table>

重要的部分是:

<small th:each="report : ${user.rep orts}"
th:utext="${#strings.replace(report.name,companyName + '_','')} : ${companyName}"></small>

对于每个报告名称,我想删除 companyName 前缀。所以 TEST_filename.txt -> filename.txt

有人可以帮助我吗?

最佳答案

使用 substringAfter :

<small th:each="report : ${user.reports}"
th:utext="${#strings.substringAfter(report.name,'_'}></small>

当然,在执行此操作之前,您需要确保您的公司名称不包含下划线分隔符。

关于string - Thymeleaf 为每个字符串替换一个子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36574098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com