gpt4 book ai didi

java - 如何在 thymeleaf 中打印数组大小?

转载 作者:太空狗 更新时间:2023-10-29 22:49:00 24 4
gpt4 key购买 nike

我将 Thymeleafspring mvc 4 一起使用,但是当我想打印列表大小时我遇到了问题

<tr th:each="u : ${users}" th:id="${u.username}" class="odd gradeX">
<th></th>
<td th:text="${u.username}"></td>
<td th:text="${u.email}"></td>
<td th:switch="${u.enabled}">
<span th:case="true" class="badge badge-primary">Acitf</span>
<span th:case="false" class="badge badge-danger">Désactivée</span>
<span th:case="*" class="badge badge-dark">Inconnue</span>
</td>
<td th:switch="${u.roles}">
<span th:case="ROLE_SUPER_ADMIN">Super ADmin</span>
<span th:case="ROLE_MANGER">Manager</span>
<span th:case="ROLE_SUPERVISEUR">Superviseur</span>
<span th:case="ROLE_USER">User</span>
<span th:case="*">Inconnue</span>

</td>
<td th:text="${#calendars.format(u.creationDate,'dd/MM/yyyy hh:mm')}"></td>
<td th:text="${#calendars.format(u.lastLogin,'dd/MM/yyyy hh:mm')}"></td>
**
<td th:text="${u.engines}"></td>
<td th:text="${u.subordonnes}"></td>
**
<td></td>
</tr>

问题就在这里th:text="${u.engines}</td> . engines是我的 User 中的 ArrayList实体。我试过 th:sizeth:list但它没有用。

谁能帮帮我

已编辑

这是我的 User实体:

@OneToMany(mappedBy = "superieur")
@JsonIgnore
private List<User> subordonnes = new ArrayList<User>();

@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "USERS_ENGINES", joinColumns = @JoinColumn(name = "USER_ID"), inverseJoinColumns = @JoinColumn(name = "NUM_EQUIPMENT"))
@JsonIgnore
private List<Engine> engines = new ArrayList<Engine>();

和我的 Controller 方法:

@RequestMapping(value = {"/listeUsers"})
public ModelAndView userlistePage() {
ModelAndView model = new ModelAndView();
User logedUser = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

List<User> users = new ArrayList<User>();
users = userService.findUserSub(logedUser);
model.addObject("users", users);
model.setViewName("utilisateur/list_users");
return model;
}

最佳答案

尝试使用 org.thymeleaf.expression.Lists 的实用方法:

<td th:text="${#lists.size(u.engines)}">[Engine Size]</td>

关于java - 如何在 thymeleaf 中打印数组大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43484142/

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