返回结果排序

HqlHelper配置

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

例子

    @Autowired
    private HqlHelperService helperService;

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

结果:

    select
        city0_.sort_seq as col_0_0_,
        city0_.name as col_1_0_,
        city0_.id as col_2_0_ 
    from
        dodo_city city0_ 
    order by
        city0_.sort_seq desc limit ?

cityList=Records [rawData=[
    {name=, sortSeq=344, id=111222333}, 
    {name=省直辖县级行政单位, sortSeq=343, id=1160799107483881472}, 
    {name=三亚市, sortSeq=342, id=1160799107169308672}]]
Copyright © Dodo Framework 2019 all right reservedModify At: 2019-12-25 11:48:19