List<Map<String, String>> 多字段排序
页面传入的多个排序字段
排序字段
public class ReFormSort { //"列名" private String columnEname; //"ASC升序,DESC降序" private String sort; }
代码里进行多字段排序
List<Map<String, String>> content = formDataService.searchFormData(paras); List<ReFormSort> sorts = paras.getSorts(); //多个排序字段 for (int i = 0; i < sorts.size(); i++) { String columnEname = sorts.get(i).getColumnEname(); if (!StringUtils.isEmpty(sorts.get(i).getColumnEname()) && "asc".equals(sorts.get(i).getSort())) { //正序 content.sort(Comparator.comparing((Map<String, String> h) -> (h.get(columnEname)))); } if (!StringUtils.isEmpty(sorts.get(i).getColumnEname()) && "desc".equals(sorts.get(i).getSort())) { content.sort(Comparator.comparing((Map<String, String> h) -> (h.get(columnEname))).reversed()); //倒序 } }
传送门 :->