sqlMap.where 新增 条件嵌套查询,可替代 andBracket、orBracket、endBracket

This commit is contained in:
thinkgem
2023-01-29 14:37:16 +08:00
parent 1b22ee0591
commit 926c25c18b

View File

@@ -4,15 +4,6 @@
*/ */
package com.jeesite.test; package com.jeesite.test;
import java.util.Date;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import com.jeesite.common.collect.ListUtils; import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.entity.DataScope; import com.jeesite.common.entity.DataScope;
import com.jeesite.common.entity.Page; import com.jeesite.common.entity.Page;
@@ -20,18 +11,16 @@ import com.jeesite.common.mybatis.mapper.query.QueryType;
import com.jeesite.common.tests.BaseSpringContextTests; import com.jeesite.common.tests.BaseSpringContextTests;
import com.jeesite.modules.file.dao.FileUploadDao; import com.jeesite.modules.file.dao.FileUploadDao;
import com.jeesite.modules.file.entity.FileUpload; import com.jeesite.modules.file.entity.FileUpload;
import com.jeesite.modules.sys.dao.AreaDao; import com.jeesite.modules.sys.dao.*;
import com.jeesite.modules.sys.dao.CompanyDao; import com.jeesite.modules.sys.entity.*;
import com.jeesite.modules.sys.dao.ConfigDao; import org.junit.Assert;
import com.jeesite.modules.sys.dao.DictDataDao; import org.junit.Test;
import com.jeesite.modules.sys.dao.EmpUserDao; import org.springframework.beans.factory.annotation.Autowired;
import com.jeesite.modules.sys.dao.UserDao; import org.springframework.boot.test.context.SpringBootTest;
import com.jeesite.modules.sys.entity.Area; import org.springframework.test.context.ActiveProfiles;
import com.jeesite.modules.sys.entity.Company;
import com.jeesite.modules.sys.entity.Config; import java.util.Date;
import com.jeesite.modules.sys.entity.DictData; import java.util.List;
import com.jeesite.modules.sys.entity.EmpUser;
import com.jeesite.modules.sys.entity.User;
/** /**
* Mapper测试 * Mapper测试
@@ -165,6 +154,7 @@ public class DaoMapperTest extends BaseSpringContextTests {
} }
} }
@Test
public static void main(String[] args) { public static void main(String[] args) {
String a = null, b = null; String a = null, b = null;
System.out.println("============ 基本测试 ============"); System.out.println("============ 基本测试 ============");
@@ -298,6 +288,27 @@ public class DaoMapperTest extends BaseSpringContextTests {
+ " #{sqlMap.where.create_by#IN1.val[1]} ) AND u.`user_name` LIKE #{sqlMap.where#user_name#LIKE1}"; + " #{sqlMap.where.create_by#IN1.val[1]} ) AND u.`user_name` LIKE #{sqlMap.where#user_name#LIKE1}";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(a, b); System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(a, b);
System.out.println("============ 条件嵌套查询,可替代 andBracket、orBracket、endBracket v5.2.1+ ============");
a = new Config("1").getSqlMap().getWhere()
.and("name", QueryType.EQ, "abc", 1)
.and((w) -> w
.or("name", QueryType.EQ, "def", 2)
.or("name", QueryType.EQ, "ghi", 3))
.and((w) -> w
.or((w2) -> w2
.and("name", QueryType.EQ, "def", 4)
.and("name", QueryType.EQ, "", 5)
.and("name", QueryType.EQ_FORCE, "", 6))
.or((w2) -> w2
.and("name", QueryType.EQ, "def", 7)
.and("name", QueryType.EQ, "ghi", 8)))
.toSql();
b = "a.`id` = #{sqlMap.where#id#EQ1} AND a.name = #{sqlMap.where.name#EQ1.val}" +
" AND (a.name = #{sqlMap.where.n#[0].name#EQ2.val} OR a.name = #{sqlMap.where.n#[0].name#EQ3.val})" +
" AND ((a.name = #{sqlMap.where.n#[1].n#[0].name#EQ4.val} AND a.name = #{sqlMap.where.n#[1].n#[0].name#EQ_FORCE6.val})" +
" OR (a.name = #{sqlMap.where.n#[1].n#[1].name#EQ7.val} AND a.name = #{sqlMap.where.n#[1].n#[1].name#EQ8.val}))";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(a, b);
System.exit(0); System.exit(0);
} }
} }