diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/KtAbstractWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/KtAbstractWrapper.java index 8108791..abf744f 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/KtAbstractWrapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/KtAbstractWrapper.java @@ -996,6 +996,12 @@ public abstract class KtAbstractWrapper 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, diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/JoinAbstractWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/JoinAbstractWrapper.java index 23f0ac2..8f27151 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/JoinAbstractWrapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/JoinAbstractWrapper.java @@ -439,6 +439,12 @@ public abstract class JoinAbstractWrapper String.format("(%s)", inValue))); } + @Override + public Children eqSql(boolean condition, String alias, SFunction column, String inValue) { + return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(index, alias, column), EQ, + () -> String.format("(%s)", inValue))); + } + @Override public Children groupBy(boolean condition, String alias, List> columns) { return maybeDo(condition, () -> { @@ -1110,6 +1116,12 @@ public abstract class JoinAbstractWrapper 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, diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Func.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Func.java index 0e7b114..38144c1 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Func.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Func.java @@ -311,6 +311,30 @@ public interface Func extends Serializable { */ Children leSql(boolean condition, String alias, SFunction column, String inValue); + default Children eqSql(SFunction column, String inValue) { + return eqSql(true, null, column, inValue); + } + + default Children eqSql(String alias, SFunction column, String inValue) { + return eqSql(true, alias, column, inValue); + } + + default Children eqSql(boolean condition, SFunction column, String inValue) { + return eqSql(condition, null, column, inValue); + } + + /** + * 字段 <= ( sql语句 ) + *

例1: leSql("id", "1, 2, 3, 4, 5, 6")

+ *

例1: leSql("id", "select id from table where name = 'JunJun'")

+ * + * @param condition 执行条件 + * @param column 字段 + * @param inValue sql语句 ---> 1,2,3,4,5,6 或者 select id from table where id < 3 + * @return children + */ + Children eqSql(boolean condition, String alias, SFunction column, String inValue); + default Children groupBy(SFunction column) { return groupBy(true, (String) null, column); } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/FuncStr.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/FuncStr.java index 570636a..2fb1d38 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/FuncStr.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/FuncStr.java @@ -228,6 +228,25 @@ public interface FuncStr extends Serializable { */ Children leSql(boolean condition, R column, String inValue); + /** + * ignore + */ + default Children eqSql(R column, String inValue) { + return eqSql(true, column, inValue); + } + + /** + * 字段 = ( sql语句 ) + *

例1: eqSql("id", "1, 2, 3, 4, 5, 6")

+ *

例1: eqSql("id", "select id from table where name = 'JunJun'")

+ * + * @param condition + * @param column + * @param inValue + * @return + */ + Children eqSql(boolean condition, R column, String inValue); + /** * ignore */ diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/EqSqlTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/EqSqlTest.java new file mode 100644 index 0000000..eec0b25 --- /dev/null +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/EqSqlTest.java @@ -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(); + } + +}