子查询 1.5.2+
支持范围
- eq
- ne
- gt
- ge
- lt
- le
- in
- notIn
- exists
- notExists
- isNull
- isNotNull
API
以eq为例
java
/**
* 参数说明
*
* @param colum eq对应的列
* @param queryClass 子查询对应的主表类
* @param wrapper 子查询构造器
*/
eq(SFunction colum, Class queryClass, Function wrapper);
/**
* 条件重载 condition 为 false 时不添加条件
*/
eq(boolean condition, SFunction colum, Class queryClass, Function wrapper);
示例
以in为例
java
MPJLambdaWrapper<User> wrapper = JoinWrappers.lambda(User.class)
.selectAll()
.leftJoin(Address.class, Address::getUserId, User::getId)
.in(User::getId, User.class, in -> in
.select(User::getId)
.between(User::getId, 0, 100));
wrapper.list();
对应sql
sql
SELECT t.id,
t.pid,
t.`name`,
t.`json`,
t.sex,
t.head_img,
t.create_time
FROM `user` t
LEFT JOIN address t1 ON (t1.user_id = t.id)
WHERE t.id IN (SELECT t.id FROM `user` t WHERE (t.id BETWEEN ? AND ?))
子查询别名
setAlias
java
MPJLambdaWrapper<User> wrapper = JoinWrappers.lambda(User.class)
.selectAll()
.leftJoin(Address.class, Address::getUserId, User::getId)
.in(User::getId, User.class, in -> in
.setAlias("sub")
.select(User::getId)
.between(User::getId, 0, 100));
wrapper.list();
对应sql
sql
SELECT t.id,
t.pid,
t.`name`,
t.`json`,
t.sex,
t.head_img,
t.create_time
FROM `user` t
LEFT JOIN address t1 ON (t1.user_id = t.id)
WHERE t.id IN (SELECT sub.id FROM `user` sub WHERE sub.del = false AND (sub.id BETWEEN ? AND ?))
提示
过于复杂的需求或sql不推荐使用
不易维护,建议使用xml