添加查找字段

HqlHelper配置

方法 等价HQL片段
fetch(String... fromClazzFieldNames) select fromClazz.fieldName1,fromClazz.fieldName2 ... fromClazz.fieldNamen
from ...
fetchOther(String tableAlias, String fieldName, String alias) select tableAlias.fieldName as alias
from ...

例子

    @Autowired
    private HqlHelperService helperService;

    @Test
    public void testHql() {
        // 一个基本的查询例子 - 查询列表
        // 查询所有城市名称以及归属的省份名称,返回2条记录
        HqlHelper helper = HqlHelper.queryFrom(City.class);
        helper.fetch("name")
              .join(HqlHelper.currTable, "province", "p")
              .fetchOther("p", "name", "provinceName")
              .setFirstResult(0).setMaxResults(2);
        Records cityList = helperService.getRecords(helper, false);
        System.err.println("cityList=" + cityList);
    }

结果:

    select
        province1_.name as col_0_0_,
        city0_.name as col_1_0_ 
    from
        dodo_city city0_ 
    inner join
        dodo_province province1_ 
            on city0_.province_id=province1_.id limit ?

cityList=Records [rawData=[
    {name=新名称, provinceName=福建}, 
    {name=莆田市, provinceName=福建}]]
Copyright © DodoFramework 2020 all right reservedModify At: 2019-12-25 11:47:51