本文介绍了如何在百里香叶中打印数组大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将 Thymeleaf 与 spring mvc 4 一起使用,但是当我想打印列表大小时遇到问题
I'm using Thymeleaf with spring mvc 4 but I have a problem when I want to print a list size
<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:size
和 th:list
但没用.
the problem is here th:text="${u.engines}</td>
. engines
is an ArrayList in my User
entity. I tried th:size
and th:list
but it didn't work.
谁能帮帮我
这是我的 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>();
和我的控制器方法:
@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
的实用方法:
Try using the utility method for org.thymeleaf.expression.Lists
:
<td th:text="${#lists.size(u.engines)}">[Engine Size]</td>
这篇关于如何在百里香叶中打印数组大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!