mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
添加 eqSql api
This commit is contained in:
parent
7eb5605fff
commit
67aa1b106a
@ -996,6 +996,12 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
||||
() -> String.format("(%s)", inValue)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children eqSql(boolean condition, String column, String inValue) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), EQ,
|
||||
() -> String.format("(%s)", inValue)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children notInSql(boolean condition, String column, String inValue) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), NOT_IN,
|
||||
|
@ -439,6 +439,12 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
() -> String.format("(%s)", inValue)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> Children eqSql(boolean condition, String alias, SFunction<R, ?> column, String inValue) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(index, alias, column), EQ,
|
||||
() -> String.format("(%s)", inValue)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> Children groupBy(boolean condition, String alias, List<SFunction<R, ?>> columns) {
|
||||
return maybeDo(condition, () -> {
|
||||
@ -1110,6 +1116,12 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
() -> String.format("(%s)", inValue)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children eqSql(boolean condition, String column, String inValue) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), EQ,
|
||||
() -> String.format("(%s)", inValue)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children notInSql(boolean condition, String column, String inValue) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), NOT_IN,
|
||||
|
@ -311,6 +311,30 @@ public interface Func<Children> extends Serializable {
|
||||
*/
|
||||
<R> Children leSql(boolean condition, String alias, SFunction<R, ?> column, String inValue);
|
||||
|
||||
default <R> Children eqSql(SFunction<R, ?> column, String inValue) {
|
||||
return eqSql(true, null, column, inValue);
|
||||
}
|
||||
|
||||
default <R> Children eqSql(String alias, SFunction<R, ?> column, String inValue) {
|
||||
return eqSql(true, alias, column, inValue);
|
||||
}
|
||||
|
||||
default <R> Children eqSql(boolean condition, SFunction<R, ?> column, String inValue) {
|
||||
return eqSql(condition, null, column, inValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段 <= ( sql语句 )
|
||||
* <p>例1: leSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||
* <p>例1: leSql("id", "select id from table where name = 'JunJun'")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param inValue sql语句 ---> 1,2,3,4,5,6 或者 select id from table where id < 3
|
||||
* @return children
|
||||
*/
|
||||
<R> Children eqSql(boolean condition, String alias, SFunction<R, ?> column, String inValue);
|
||||
|
||||
default <R> Children groupBy(SFunction<R, ?> column) {
|
||||
return groupBy(true, (String) null, column);
|
||||
}
|
||||
|
@ -228,6 +228,25 @@ public interface FuncStr<Children, R> extends Serializable {
|
||||
*/
|
||||
Children leSql(boolean condition, R column, String inValue);
|
||||
|
||||
/**
|
||||
* ignore
|
||||
*/
|
||||
default Children eqSql(R column, String inValue) {
|
||||
return eqSql(true, column, inValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段 = ( sql语句 )
|
||||
* <p>例1: eqSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||
* <p>例1: eqSql("id", "select id from table where name = 'JunJun'")</p>
|
||||
*
|
||||
* @param condition
|
||||
* @param column
|
||||
* @param inValue
|
||||
* @return
|
||||
*/
|
||||
Children eqSql(boolean condition, R column, String inValue);
|
||||
|
||||
/**
|
||||
* ignore
|
||||
*/
|
||||
|
@ -0,0 +1,31 @@
|
||||
package com.github.yulichang.test.join.m;
|
||||
|
||||
import com.github.yulichang.test.join.entity.UserDO;
|
||||
import com.github.yulichang.test.util.Reset;
|
||||
import com.github.yulichang.test.util.ThreadLocalUtils;
|
||||
import com.github.yulichang.toolkit.JoinWrappers;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
public class EqSqlTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Reset.reset();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void eqSql() {
|
||||
ThreadLocalUtils.set("SELECT t.id, t.pid, t.`name`, t.`json`, t.sex, t.head_img, t.create_time, t.address_id, " +
|
||||
"t.address_id2, t.del, t.create_by, t.update_by FROM `user` t WHERE t.del = false AND (t.id = (SELECT id FROM `user` LIMIT 1))");
|
||||
JoinWrappers.lambda(UserDO.class).eqSql(UserDO::getId, "select id from `user` limit 1").list();
|
||||
|
||||
ThreadLocalUtils.set("SELECT t.id, t.pid, t.`name`, t.`json`, t.sex, t.head_img, t.create_time, t.address_id, " +
|
||||
"t.address_id2, t.del, t.create_by, t.update_by FROM `user` t WHERE t.del = false AND (t.id = (SELECT id FROM `user` LIMIT 1))");
|
||||
JoinWrappers.lambda(UserDO.class).eqSql("t.id", "select id from `user` limit 1").list();
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user