List<WaPayFileVO> list =(List<WaPayFileVO>) dao.execQueryBeanList(pagesql, params.toArray(), new BeanListProcessor(WaPayFileVO.class)); if("asc".equals(page.getOrder()) && "pk_psnjob__pk_psndoc__name".equals(page.getSort())){ Collections.sort(list, new Comparator<WaPayFileVO>() { @Override public int compare(WaPayFileVO o1, WaPayFileVO o2) { return Collator.getInstance(Locale.CHINESE).compare(o1.getPk_psnjob__pk_psndoc__name(),o2.getPk_psnjob__pk_psndoc__name()); } }); }else if("desc".equals(page.getOrder()) && "pk_psnjob__pk_psndoc__name".equals(page.getSort())){ Collections.sort(list, new Comparator<WaPayFileVO>() { @Override public int compare(WaPayFileVO o1, WaPayFileVO o2) { return -Collator.getInstance(Locale.CHINESE).compare(o1.getPk_psnjob__pk_psndoc__name(),o2.getPk_psnjob__pk_psndoc__name()); } }); }
jdk自带的Collator包涵的汉字太少了,对一些生僻的姓氏不能进行排序。推荐使用:
import com.ibm.icu.text.Collator;
是ibm开发的针对编码的工具包,非常好用。附pom文件:
<dependency> <groupId>com.ibm.icu</groupId> <artifactId>icu4j</artifactId> <version>57.1</version> </dependency>