FreeMarker中List排序

有时候需要在页面上对list排序,虽然也可以在后台代码中完成,但这个可能要看具体情况。
排序的样本代码如下:

<#list resultMap.topViewList?sort_by("monthlyViewedCount") as tvl>
.............................................
</#list>

monthlyViewedCount是list中对象的属性。默认情况下是升序,如果你要降序:

<#list resultMap.topViewList?sort_by("monthlyViewedCount")?reverse as tvl>
.............................................
</#list>