添加查找字段

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 …

例子

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

结果:

  1. select
  2. province1_.name as col_0_0_,
  3. city0_.name as col_1_0_
  4. from
  5. dodo_city city0_
  6. inner join
  7. dodo_province province1_
  8. on city0_.province_id=province1_.id limit ?
  9. cityList=Records [rawData=[
  10. {name=新名称, provinceName=福建},
  11. {name=莆田市, provinceName=福建}]]