如何在百里香叶中打印阵列大小?
2022-09-02 00:17:56
我正在使用带有弹簧mvc 4的Thymeleaf,但是当我想打印列表大小时,我有一个问题
<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>
问题就在这里。 是我实体中的 ArrayList。我试过了,但它不起作用。th:text="${u.engines}</td>
engines
User
th:size
th: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>();
和我的控制器方法:
@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;
}