Order by in Thymeleaf

喜你入骨 提交于 2019-12-25 01:32:12

问题


I need show this foreach by order Asc, how can I do it?

<tr th:each="ment : ${mentor}" th:if="${ment.jobId == job.id}">
    <td th:text="${ment.id}"></td>
    <td th:text="${ment.name}"></td>
    <td th:text="${ment.qtyMentee}"></td>
    <td th:text="${ment.jobId}"></td>
</tr>

回答1:


This could be achieved with sort utility methods for lists, described here.

/*
 * Sort a copy of the given list. The members of the list must implement
 * comparable or you must define a comparator.
 */
${#lists.sort(list)}
${#lists.sort(list, comparator)}

Example

<tr th:each="ment : ${#lists.sort(mentor)}">


来源:https://stackoverflow.com/questions/29168979/order-by-in-thymeleaf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!