Skip to content Skip to sidebar Skip to footer

Order By In Thymeleaf

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

Solution 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)}">

Solution 2:

I had StackOverflow also, in my case I forgot to implement Comparable:

 Comparable<E>

The error was missleading, thymeleaf could recognize that compareable needs to be implemented.

Post a Comment for "Order By In Thymeleaf"