mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-06 16:48:24 +08:00
feat: 添加 QueryWrapper 的 Plus 兼容 api
This commit is contained in:
parent
9787f020a1
commit
baf185af93
@ -59,6 +59,27 @@ public class QueryWrapper extends BaseQueryWrapper<QueryWrapper> {
|
||||
return tableInfo.buildQueryWrapper(entity, operators);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 Map 对象,构建查询条件
|
||||
*
|
||||
* @param map Map 对象
|
||||
* @return 查询对象 QueryWrapper
|
||||
*/
|
||||
public static QueryWrapper create(Map map) {
|
||||
return create().where(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 Map 构建查询条件
|
||||
*
|
||||
* @param map Map 对象
|
||||
* @param operators 每个属性对应的操作符
|
||||
* @return 查询对象 QueryWrapper
|
||||
*/
|
||||
public static QueryWrapper create(Map map, SqlOperators operators) {
|
||||
return create().where(map, operators);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <Q extends QueryWrapper> WithBuilder<Q> with(String name) {
|
||||
@ -1331,7 +1352,6 @@ public class QueryWrapper extends BaseQueryWrapper<QueryWrapper> {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* {@code IN(value)}
|
||||
*
|
||||
|
||||
@ -35,7 +35,7 @@ public class PlusCompatibleTest {
|
||||
.eq("column1", value1, If::hasText)
|
||||
.ge(Account::getAge, 18)
|
||||
.or(qw -> {
|
||||
qw.like("column2", "value2");
|
||||
qw.likeLeft("column2", "value2");
|
||||
})
|
||||
.or(q1 -> {
|
||||
q1.eq("column3", "value3")
|
||||
@ -44,7 +44,7 @@ public class PlusCompatibleTest {
|
||||
|
||||
Assert.assertEquals("SELECT * FROM `user` " +
|
||||
"WHERE `tb_account`.`age` >= 18 " +
|
||||
"OR (column2 LIKE '%value2%') " +
|
||||
"OR (column2 LIKE 'value2%') " +
|
||||
"OR (column3 = 'value3' AND `tb_account`.`sex` >= 0)"
|
||||
, queryWrapper.toSQL());
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user