添加查询条件

更多可惨见HqlHelper源码注释

(1/5)基本查询条件

无 tableAlias 参数的重载方法,tableAlias=HqlHelper.currTable 即:fromClazz 的别名

方法 等价HQL片段
eq,ne,ge,gt,lt,le(String tableAlias, String fieldName, Object value) tableAlias.fieldName =,!=,>=,>,<,<= value
in,notIn(String tableAlias, String fieldName, Object... values) tableAlias.fieldName in,not in values
like,notLike(String tableAlias, String fieldName, String value, MatchType matchType) tableAlias.fieldName like,not like matchType:value
ilike,notiLike(String tableAlias, String fieldName, String value, MatchType matchType) upper(tableAlias.fieldName) like,not like upper(matchType:value)
like,notLike(String tableAlias, String fieldName, String value) tableAlias.fieldName like,not like '%value%'
ilike,notiLike(String tableAlias, String fieldName, String value) upper(tableAlias.fieldName) like,not like upper('%value%')
isNull,isNotNull(String tableAlias, String fieldName) tableAlias.fieldName is null,is not null
between,notBetween(String tableAlias, String fieldName, Object value1, Object value2) tableAlias.fieldName between,not between value1 and value2

(2/5)双字段查询条件

无 tableAlias 参数的重载方法,tableAlias=HqlHelper.currTable 即:fromClazz 的别名

方法 等价HQL片段
eq,ne,ge,gt,lt,leProperty(String tableAlias, String fieldName, String otherTableAlias, String otherFieldName) tableAlias.fieldName =,!=,>=,>,<,<= otherTableAlias.otherFieldName

(3/5)集合查询条件:一般不用

无 tableAlias 参数的重载方法,tableAlias=HqlHelper.currTable 即:fromClazz 的别名

方法 等价HQL片段
sizeEq,Ge,Gt,Le,Lt,Ne(String tableAlias, String fieldName, Integer size) size(tableAlias.fieldName) =,>=,>,<=,<,!= size
isEmpty,isNotEmpty(String tableAlias, String fieldName) tableAlias.fieldName is empty,is not empty

(4/5)字符串长度查询条件:一般不用

无 tableAlias 参数的重载方法,tableAlias=HqlHelper.currTable 即:fromClazz 的别名

方法 等价HQL片段
lengthEq,Ge,Gt,Le,Lt,Ne(String tableAlias, String fieldName, Integer length) length(tableAlias.fieldName) =,>=,>,<=,<,!= length
lengthEq,Ge,Gt,Le,Lt,NeProperty(String tableAlias, String fieldName, String otherTableAlias, String otherFieldName) length(tableAlias.fieldName) =,>=,>,<=,<,!= length(otherTableAlias.otherFieldName)

(5/5)条件分组

 .and().条件1.条件2.end()  等价HQL片段 : and (条件1 and 条件2) 
 .or().条件1.条件2.end()   等价HQL片段 : or (条件1 and 条件2)

例子:

    @Test
    public void conditionGroup() {
        // 查询sortSeq>98,并且名称包含`天`或者`庆`字的城市  查询2条记录
        HqlHelper helper = HqlHelper.queryFrom(City.class);
        helper.fetch("id", "name")
              .gt("sortSeq", 98)
              .and()
                .like("name", "天").or().like("name", "庆").end()
              .end()
              .setFirstResult(0).setMaxResults(2);
        Records tempRecords = helperService.getRecords(helper, false);
        System.err.println(tempRecords);
    }

结果:

    select
        city0_.id as col_0_0_,
        city0_.name as col_1_0_ 
    from
        dodo_city city0_ 
    where
        city0_.sort_seq>? 
        and (
            city0_.name like ? 
            or city0_.name like ?
        ) limit ?

Records [rawData=[
    {name=安庆市, id=1160799058548936704}, 
    {name=重庆市, id=1160799060084051968}]]
Copyright © Dodo Framework 2019 all right reservedModify At: 2019-12-25 11:45:51