根据情况生成不同的查询条件(in、like)
最后更新:2024-03-12 11:08:13
|
状态:未完成
场景与上一步一样。只是拼接的SQL更费代码一点
根据情况生成
SELECT * FROM HR_EMPLOYEE WHERE TYPE_CODE IN(?,?,?)
SELECT * FROM HR_EMPLOYEE WHERE NAME LIKE '?%' ‘%?’ ‘%?%’ 等各种情况
根据情况生成
SELECT * FROM HR_EMPLOYEE WHERE TYPE_CODE IN(?,?,?)
SELECT * FROM HR_EMPLOYEE WHERE NAME LIKE '?%' ‘%?’ ‘%?%’ 等各种情况
- anyline
- ORM
- 全部展开
【anyline】
- 通过GET形式,http://localhost/list?type=1&type=2&type=3
- 通过GET形式,http://localhost/list?type=1,2,3
- 通过form提交
- 通过json形式{"type":["1","2","3"]}
1 2 3 4 5 6 7 8 | //IN DataSet set = service.querys( "HR_EMPLOYEE" , condition( "TYPE_CODE:[types]" )) //LIKE DataSet set = service.querys( "HR_EMPLOYEE" , condition( "NAME:%name%" )) 或 condition( "NAME:%name" ) condition( "NAME:name%" ) |
【ORM】
各种判断、遍历是少不了的,这种常用的功能应该是内置的,不明白为什么要浪费程序员时间
//IN
先在Java中接收types参数封闭成Collection格式
1 2 3 4 5 6 | < if test="types != null and types.size > 0"> and TYPE_CODE in < foreach collection = "types" item = "type" open = "(" separator = "," close = ")" > #{type} </ foreach > </ if > |
//LIKE 3种情况要挨个写一遍?是不是有更抽象的方法可以概括一下?这里的name如果有空格在if阶段是怎么处理的呢?
1 2 3 | < if test = "name != null and name != ''" > and case_no like concat('%',trim( #{name}),'%') </ if > < if test = "name != null and name != ''" > and case_no like concat(trim( #{name}),'%') </ if > < if test = "name != null and name != ''" > and case_no like concat('%',trim( #{name})) </ if > |