Thymeleaf 文档说明了排序列表:
/*
* 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)}
在我的文档模型中,我有一个带有键值对的映射published_content
列表(来自 JBake 静态页面生成器的列表)。在我的模板中,我想通过比较存储在地图中某个键下的值来对该列表进行排序。
换句话说,list
变量具有类型List<Map<String, Object>>
,我想通过比较存储在 key 下的每个映射中的值来对该列表进行排序"mykey"
。
如何在模板中制定这样的比较器?