返回结果排序

HqlHelper配置

方法等价HQL片段
orderBy (String fromClazzFieldName, OrderType orderType)order by fromClazz.fromClazzFieldName orderType
orderBy (String tableAlias, String fieldName, OrderType orderType)order by tableAlias.fieldName orderType

例子

  1. @Autowired
  2. private HqlHelperService helperService;
  3. @Test
  4. public void testHql() {
  5. // 查询城市名称、序号,按照序号降序排列,读取3条记录
  6. HqlHelper helper = HqlHelper.queryFrom(City.class);
  7. helper.fetch("sortSeq", "name")
  8. .orderBy("sortSeq", OrderType.desc)
  9. .setFirstResult(0).setMaxResults(3);
  10. Records cityList = helperService.getRecords(helper, false);
  11. System.err.println("cityList=" + cityList);
  12. }

结果:

  1. select
  2. city0_.sort_seq as col_0_0_,
  3. city0_.name as col_1_0_,
  4. city0_.id as col_2_0_
  5. from
  6. dodo_city city0_
  7. order by
  8. city0_.sort_seq desc limit ?
  9. cityList=Records [rawData=[
  10. {name=, sortSeq=344, id=111222333},
  11. {name=省直辖县级行政单位, sortSeq=343, id=1160799107483881472},
  12. {name=三亚市, sortSeq=342, id=1160799107169308672}]]