动态SQL条件

说明

hsweb定义了一种支持动态条件的数据结构:

{  //where name like 张%
    terms:[
        {
            column:"name", //属性名或者列名
            value:"张", //值,为null或者为""时,此条件将被忽略
            type:"and", // 连接类型,and 或者 or
            termType:"like", // like
            options:["startWith"], //可选项,不同的termType支持不同.
            terms:[
                //嵌套,结构同上
                
            ]
        }
    ]
}

对应的Java类有: QueryParamEntityUpdateParamEntityDeleteParamEntity

DSL

hsweb提供了通过DSL的方式来构造上述结构,用例:

如果继承了GenericEntityService的类可以直接使用DSL进行查询,修改,删除操作

上述例子中 name$like$startWith的含义: name(列), like(条件),startWith(条件选项)

默认支持的SQL条件

termType

SQL

DSL

说明

is 或者 eq

=

.is()

等于

not

!=

.not()

不等于

gt

>

.gt()

大于

lt

<

.lt()

小于

gte

>=

.gte()

大于等于

lte

<=

.lte()

小于等于

like

like

.like()

模糊匹配.支持options

  1. reverse 反转,如: ? like name

  2. startWith: like ?||%

  3. endWith: like %||?

nlike

not like

.notLike()

同like

in

in

.in()

值可以为以下格式:

  1. 1,2,3,4 字符串以半角逗号分割.

  2. [1,2,3,4] 集合.

nin

not in

.notIn()

同in

isnull

is null

.isNull()

为null

notnull

not null

.notNull()

不为null

empty

= ''

.isEmpty()

为空字符

nempty

!=''

.notEmpty()

不为字符

bwt

between

.between()

在之间

nbwt

not between

.notBetween

不在之间

自定义SQL条件

上述默认支持的SQL条件其实就是用来定义列与条件的拼接方式。在某些场景,我们可能需要定义一些通用的查询条件。

例如: 根据部门ID 查询所有此部门下所有人员的数据,而且有很多功能都要使用此条件。

创建拓展类

使用:

组织架构功能中,提供了一些已经拓展好的SQL条件。

Last updated

Was this helpful?