voList = Binder.convertAndBindRelations(userList, EntityBinderVO.class);
+ for(EntityBinderVO vo : voList){
+ // 验证直接关联和通过中间表间接关联的绑定
+ Assert.assertEquals(vo.getDepartmentId(), vo.getDepartment2().getId());
+ Assert.assertNotNull(vo.getDepartment2().getOrgId());
+ if(vo.getId().equals(1004L)){
+ Assert.assertNotNull(vo.getDepartment2().getExtjsonarr());
+ }
+ }
+ }
+
}
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestEntityListBinder.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestEntityListBinder.java
index aa60c715d4fbcae50770fca1ecb05669e6e18be6..72ea7e7069000ac8058c4a9ae07b3cf415f1ede5 100644
--- a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestEntityListBinder.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestEntityListBinder.java
@@ -20,6 +20,7 @@ import com.diboot.core.binding.Binder;
import com.diboot.core.entity.Dictionary;
import com.diboot.core.service.DictionaryService;
import com.diboot.core.util.JSON;
+import com.diboot.core.util.S;
import com.diboot.core.util.V;
import com.diboot.core.vo.DictionaryVO;
import diboot.core.test.StartupApplication;
@@ -141,14 +142,16 @@ public class TestEntityListBinder {
for(SimpleSplitVO vo : voList){
// 验证通过中间表间接关联的绑定
Assert.assertTrue(V.notEmpty(vo.getManagers()));
- System.out.println(JSON.stringify(vo));
+ //System.out.println(JSON.stringify(vo));
if(vo.getCharacter().contains(",")){
- String[] valueArr = vo.getCharacter().split(",");
+ String[] valueArr = S.clearNonConst(vo.getCharacter()).split(",");
if(valueArr[0].equals(valueArr[1])){
Assert.assertTrue(vo.getManagers().size() == 1);
+ Assert.assertTrue(vo.getManagersByJson().size() == 1);
}
else{
Assert.assertTrue(vo.getManagers().size() > 1);
+ Assert.assertTrue(vo.getManagersByJson().size() > 1);
}
}
else{
@@ -172,10 +175,11 @@ public class TestEntityListBinder {
// 验证通过中间表间接关联的绑定
if(vo.getManagerId().equals(1001L)){
Assert.assertTrue(vo.getManagerPhotos().size() == 1);
- Assert.assertEquals(1, vo.getManagerPhotoList().size());
+ Assert.assertEquals(2, vo.getManagerPhotoList().size());
}
else{
Assert.assertTrue(vo.getManagerPhotos().size() == 2);
+ Assert.assertTrue(V.isEmpty(vo.getManagerPhotoList()));
}
System.out.println(JSON.stringify(vo));
}
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestFieldListBinder.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestFieldListBinder.java
index 107f938c4b3c9c88910868e85b49de70b8aa7fab..bfe0b08fd1cb1fe3e1ac962672a2315370f9f2d0 100644
--- a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestFieldListBinder.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestFieldListBinder.java
@@ -18,6 +18,7 @@ package diboot.core.test.binder;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.diboot.core.binding.Binder;
import com.diboot.core.util.JSON;
+import com.diboot.core.util.S;
import com.diboot.core.util.V;
import diboot.core.test.StartupApplication;
import diboot.core.test.binder.entity.DemoTest;
@@ -142,12 +143,14 @@ public class TestFieldListBinder {
Assert.assertTrue(V.notEmpty(vo.getManagerNames()));
System.out.println(JSON.stringify(vo));
if(vo.getCharacter().contains(",")){
- String[] valueArr = vo.getCharacter().split(",");
+ String[] valueArr = S.clearNonConst(vo.getCharacter()).split(",");
if(valueArr[0].equals(valueArr[1])){
Assert.assertTrue(vo.getManagerNames().size() == 1);
+ Assert.assertTrue(vo.getManagerNamesByJson().size() == 1);
}
else{
Assert.assertTrue(vo.getManagerNames().size() > 1);
+ Assert.assertTrue(vo.getManagerNamesByJson().size() > 1);
}
}
else{
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestJsonArrayBinder.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestJsonArrayBinder.java
new file mode 100644
index 0000000000000000000000000000000000000000..46c71236c95120000e4c2c17038fa919f3da85f3
--- /dev/null
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestJsonArrayBinder.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2015-2020, www.dibo.ltd (service@dibo.ltd).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package diboot.core.test.binder;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.diboot.core.binding.Binder;
+import com.diboot.core.util.JSON;
+import com.diboot.core.util.V;
+import diboot.core.test.StartupApplication;
+import diboot.core.test.binder.entity.User;
+import diboot.core.test.binder.service.UserService;
+import diboot.core.test.binder.vo.UserJsonVO;
+import diboot.core.test.config.SpringMvcConfig;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.List;
+
+/**
+ * 测试JsonArray绑定
+ * @author mazc@dibo.ltd
+ * @version v2.7.0
+ * @date 2022/09/09
+ */
+@RunWith(SpringRunner.class)
+@ContextConfiguration(classes = {SpringMvcConfig.class})
+@SpringBootTest(classes = {StartupApplication.class})
+public class TestJsonArrayBinder {
+
+ @Autowired
+ UserService userService;
+
+ /**
+ * 验证jsonarray字段的条件绑定
+ */
+ @Test
+ public void testJsonArrayBinder(){
+ // 需要先确保queryWrapper.in()支持jsonarray
+ // 加载测试数据
+ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.in(User::getId, 1001L, 1002L);
+ List entityList = userService.getEntityList(queryWrapper);
+ // 自动绑定
+ List voList = Binder.convertAndBindRelations(entityList, UserJsonVO.class);
+ // 验证绑定结果
+ Assert.assertTrue(V.notEmpty(voList));
+ for(UserJsonVO vo : voList){
+ // 验证直接关联的绑定
+ System.out.println(JSON.stringify(vo));
+ }
+ }
+
+}
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestLeadExtConditionBinder.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestLeadExtConditionBinder.java
index 8ba5a02f0db6331dd7128a7fd0bc5cfd14fb7951..3d70cf1486696ea74ae2cd8dbdfdee57d02c3607 100644
--- a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestLeadExtConditionBinder.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestLeadExtConditionBinder.java
@@ -22,7 +22,6 @@ import com.diboot.core.util.V;
import diboot.core.test.StartupApplication;
import diboot.core.test.binder.entity.User;
import diboot.core.test.binder.service.UserService;
-import diboot.core.test.binder.vo.FieldBinderVO;
import diboot.core.test.binder.vo.UserExtVO;
import diboot.core.test.config.SpringMvcConfig;
import org.junit.Assert;
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java
index 7679ff3445fd472a509b3928ebdb4322a0b3b463..882f63f2b2d5717764cbd063bea4b5e405635234 100644
--- a/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java
@@ -18,6 +18,7 @@ package diboot.core.test.binder.dto;
import com.baomidou.mybatisplus.annotation.TableField;
import com.diboot.core.binding.query.BindQuery;
import com.diboot.core.binding.query.Comparison;
+import com.diboot.core.binding.query.Strategy;
import com.diboot.core.util.D;
import diboot.core.test.binder.entity.Department;
import diboot.core.test.binder.entity.Organization;
@@ -43,11 +44,11 @@ public class DepartmentDTO implements Serializable {
private Long parentId;
- @BindQuery(comparison = Comparison.CONTAINS)
+ @BindQuery(comparison = Comparison.LIKE, strategy = Strategy.IGNORE_EMPTY)
private String name;
// 绑定join查询
- @BindQuery(comparison = Comparison.STARTSWITH, entity = Organization.class, field = "name", condition = "this.org_id=id")
+ @BindQuery(comparison = Comparison.STARTSWITH, strategy = Strategy.INCLUDE_NULL, entity = Organization.class, field = "name", condition = "this.org_id=id")
private String orgName;
// 绑定join查询
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Customer.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Customer.java
new file mode 100644
index 0000000000000000000000000000000000000000..2845e7526cb7818ee118b37e67af3630db189cdb
--- /dev/null
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Customer.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2015-2020, www.dibo.ltd (service@dibo.ltd).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package diboot.core.test.binder.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
+import com.diboot.core.entity.BaseEntity;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.experimental.Accessors;
+
+import java.util.List;
+
+/**
+ * @author mazc@dibo.ltd
+ * @version v2.0
+ * @date 2019/1/30
+ */
+@Getter
+@Setter
+@Accessors(chain = true)
+@TableName(autoResultMap = true)
+public class Customer extends BaseEntity {
+ private static final long serialVersionUID = 5650761344045195972L;
+
+ @TableField
+ private String realname;
+
+ @TableField
+ private String cellphone;
+
+ /**
+ * JSON数组
+ */
+ @TableField(typeHandler = JacksonTypeHandler.class)
+ private List extjsonarr;
+
+}
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Department.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Department.java
index 03abb0876f098985eee7278cb4cfa1aa50099bc5..d8da8cac63d60db4323100c503264af94009c576 100644
--- a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Department.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Department.java
@@ -16,6 +16,8 @@
package diboot.core.test.binder.entity;
import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.diboot.core.binding.query.BindQuery;
import com.diboot.core.binding.query.Comparison;
import com.diboot.core.binding.query.Strategy;
@@ -25,6 +27,9 @@ import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
+import java.util.LinkedHashMap;
+import java.util.List;
+
/**
* Department
* @author mazc@dibo.ltd
@@ -34,6 +39,7 @@ import lombok.experimental.Accessors;
@Getter
@Setter
@Accessors(chain = true)
+@TableName(autoResultMap = true)
public class Department extends BaseEntity {
private static final long serialVersionUID = -4849732665419794547L;
@@ -51,4 +57,17 @@ public class Department extends BaseEntity {
@TableField("`character`")
private String character;
+
+ /**
+ * JSON数组
+ */
+ @TableField(typeHandler = JacksonTypeHandler.class)
+ private List extjsonarr;
+
+ /**
+ * JSON对象
+ */
+ @TableField(typeHandler = JacksonTypeHandler.class)
+ private LinkedHashMap extjsonobj;
+
}
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/MyStrIdBaseEntity.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/MyStrIdBaseEntity.java
new file mode 100644
index 0000000000000000000000000000000000000000..0dc30a89b6acc5eb81052a220fe185d9efab0e1a
--- /dev/null
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/MyStrIdBaseEntity.java
@@ -0,0 +1,19 @@
+package diboot.core.test.binder.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.diboot.core.entity.AbstractEntity;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.experimental.Accessors;
+
+/**
+* 自定义String类型id的BaseEntity
+*/
+@Getter @Setter @Accessors(chain = true)
+public abstract class MyStrIdBaseEntity extends AbstractEntity {
+
+ @TableId(value = "ID_", type = IdType.ASSIGN_UUID)
+ private String id;
+
+}
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Organization.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Organization.java
index dcea77b9c409f24381d3e0f42e548f892bc5b8cd..c67224b1ae7d38c583d2f2b52ac902a2739a932e 100644
--- a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Organization.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Organization.java
@@ -36,7 +36,7 @@ public class Organization extends BaseEntity {
@TableField
private Long parentId;
- @TableField
+ //@TableField
private String name;
@TableField
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/StrIdTest.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/StrIdTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..0b8f893c5109620eb6216f853b86319330a23f28
--- /dev/null
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/StrIdTest.java
@@ -0,0 +1,29 @@
+package diboot.core.test.binder.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.experimental.Accessors;
+import org.hibernate.validator.constraints.Length;
+
+/**
+* String类型id的Entity定义
+*/
+@Getter @Setter @Accessors(chain = true)
+public class StrIdTest extends MyStrIdBaseEntity {
+
+ /**
+ * 类型
+ */
+ @Length(max=255, message="类型长度应小于255")
+ @TableField(value = "TYPE_")
+ private String type;
+
+ /**
+ * 用户ID
+ */
+ @Length(max=255, message="用户ID长度应小于255")
+ @TableField(value = "USER_ID_")
+ private String userId;
+
+}
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/TestRegion.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/TestRegion.java
index 6a09f189ffddaa30d7c8aa22b50ecd9f2e0145cc..4a813e7f3c173fbb670e4f02e6a0e9ae05b2d906 100644
--- a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/TestRegion.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/TestRegion.java
@@ -19,14 +19,10 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.diboot.core.entity.BaseEntity;
-import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
-import org.hibernate.validator.constraints.Length;
-import javax.validation.constraints.NotNull;
-import java.time.LocalDateTime;
import java.util.List;
/**
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/User.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/User.java
index 43c7712b954f162dc35695e242232a7cacced234..f18957329667c0168b902011549a1972d0bc7267 100644
--- a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/User.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/User.java
@@ -16,7 +16,6 @@
package diboot.core.test.binder.entity;
import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableName;
import com.diboot.core.data.copy.Accept;
import com.diboot.core.entity.BaseEntity;
import com.diboot.core.util.D;
@@ -50,10 +49,10 @@ public class User extends BaseEntity {
@TableField
private String gender;
- //@JsonFormat(pattern = D.FORMAT_DATE_Y4MD)
+ @JsonFormat(pattern = D.FORMAT_DATE_Y4MD)
private Date birthdate;
- @JsonFormat(pattern = D.FORMAT_DATE_Y4MD)
+ @JsonFormat(pattern = D.FORMAT_DATETIME_Y4MDHMS)
private LocalDateTime localDatetime;
@TableField("`character`")
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/mapper/CustomerMapper.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/mapper/CustomerMapper.java
new file mode 100644
index 0000000000000000000000000000000000000000..fad9b2622cd3451ed901eeb1198d1cd2dda1140f
--- /dev/null
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/mapper/CustomerMapper.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2015-2020, www.dibo.ltd (service@dibo.ltd).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package diboot.core.test.binder.mapper;
+
+import com.diboot.core.mapper.BaseCrudMapper;
+import diboot.core.test.binder.entity.Customer;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 客户Mapper
+ * @author mazc@dibo.ltd
+ * @version 2018/12/22
+ */
+@Mapper
+public interface CustomerMapper extends BaseCrudMapper {
+
+}
+
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/mapper/StrIdTestMapper.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/mapper/StrIdTestMapper.java
new file mode 100644
index 0000000000000000000000000000000000000000..2dadf47e45f7cf9737bc0e6c237aa22ea1b35474
--- /dev/null
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/mapper/StrIdTestMapper.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2015-2020, www.dibo.ltd (service@dibo.ltd).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package diboot.core.test.binder.mapper;
+
+import com.diboot.core.mapper.BaseCrudMapper;
+import diboot.core.test.binder.entity.StrIdTest;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * StrIdTest Mapper
+ * @author mazc@dibo.ltd
+ * @version 2018/12/22
+ */
+@Mapper
+public interface StrIdTestMapper extends BaseCrudMapper {
+
+}
+
diff --git a/diboot-iam-starter/src/main/java/com/diboot/iam/jwt/BaseJwtAuthToken.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/service/CustomerService.java
similarity index 65%
rename from diboot-iam-starter/src/main/java/com/diboot/iam/jwt/BaseJwtAuthToken.java
rename to diboot-core-starter/src/test/java/diboot/core/test/binder/service/CustomerService.java
index 15e72d8f2b5aaf9c95151cd78409d0e5667f87f7..4c801172715c051af4e41df80fb779e985c46898 100644
--- a/diboot-iam-starter/src/main/java/com/diboot/iam/jwt/BaseJwtAuthToken.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/service/CustomerService.java
@@ -13,21 +13,17 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.diboot.iam.jwt;
+package diboot.core.test.binder.service;
-import com.diboot.iam.shiro.IamAuthToken;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.extern.slf4j.Slf4j;
+import com.diboot.core.service.BaseService;
+import diboot.core.test.binder.entity.Customer;
/**
- * @author Yangzhao
+ * 客户相关Service
+ * @author mazc@dibo.ltd
* @version v2.0
- * @date 2019/6/6
+ * @date 2019/1/5
*/
-@Deprecated
-@Getter @Setter
-@Slf4j
-public class BaseJwtAuthToken extends IamAuthToken {
- private static final long serialVersionUID = -3455501467921544790L;
+public interface CustomerService extends BaseService {
+
}
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/service/DepartmentService.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/service/DepartmentService.java
index ff27917c88056d98012dc2aa21d3f04b92911078..19aae88b6245173771bf1ac6a80f715362f51f3a 100644
--- a/diboot-core-starter/src/test/java/diboot/core/test/binder/service/DepartmentService.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/service/DepartmentService.java
@@ -15,8 +15,9 @@
*/
package diboot.core.test.binder.service;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.service.IService;
+import com.diboot.core.service.BaseService;
import com.diboot.core.vo.Pagination;
import diboot.core.test.binder.dto.DepartmentDTO;
import diboot.core.test.binder.entity.Department;
@@ -29,7 +30,15 @@ import java.util.List;
* @version v2.0
* @date 2019/1/30
*/
-public interface DepartmentService extends IService {
+public interface DepartmentService extends BaseService {
+
+ /**
+ * 获取指定条件的Entity集合
+ * @param queryWrapper
+ * @return
+ * @throws Exception
+ */
+ List list(Wrapper queryWrapper);
List getDepartmentSqlList(QueryWrapper queryWrapper, Pagination pagination);
}
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/service/StrIdTestService.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/service/StrIdTestService.java
new file mode 100644
index 0000000000000000000000000000000000000000..e56cc662d37ce3082b8f06baf9aa60911b891dd7
--- /dev/null
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/service/StrIdTestService.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2015-2020, www.dibo.ltd (service@dibo.ltd).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package diboot.core.test.binder.service;
+
+import com.diboot.core.service.BaseService;
+import diboot.core.test.binder.entity.StrIdTest;
+
+/**
+ * StrIdTest相关Service
+ * @author mazc@dibo.ltd
+ * @version 2022/9/19
+ */
+public interface StrIdTestService extends BaseService {
+
+}
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/service/impl/CustomerServiceImpl.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/service/impl/CustomerServiceImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..a2c3dc4c6156e9e9b6ee8a19ba19f5ec4a1978e0
--- /dev/null
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/service/impl/CustomerServiceImpl.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2015-2020, www.dibo.ltd (service@dibo.ltd).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package diboot.core.test.binder.service.impl;
+
+import com.diboot.core.service.impl.BaseServiceImpl;
+import diboot.core.test.binder.entity.Customer;
+import diboot.core.test.binder.mapper.CustomerMapper;
+import diboot.core.test.binder.service.CustomerService;
+import org.springframework.stereotype.Service;
+
+/**
+ * 员工相关Service
+ * @author mazc@dibo.ltd
+ * @version 2018/12/23
+ */
+@Service
+public class CustomerServiceImpl extends BaseServiceImpl implements CustomerService {
+
+}
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/service/impl/DepartmentServiceImpl.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/service/impl/DepartmentServiceImpl.java
index a30f64b3a0b092aca312cca4d035c98a71a1a291..8f19a291635007802928994fc838d3d73d397462 100644
--- a/diboot-core-starter/src/test/java/diboot/core/test/binder/service/impl/DepartmentServiceImpl.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/service/impl/DepartmentServiceImpl.java
@@ -15,8 +15,9 @@
*/
package diboot.core.test.binder.service.impl;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.diboot.core.service.impl.BaseServiceImpl;
import com.diboot.core.vo.Pagination;
import diboot.core.test.binder.dto.DepartmentDTO;
import diboot.core.test.binder.entity.Department;
@@ -35,7 +36,12 @@ import java.util.List;
*/
@Slf4j
@Service
-public class DepartmentServiceImpl extends ServiceImpl implements DepartmentService {
+public class DepartmentServiceImpl extends BaseServiceImpl implements DepartmentService {
+
+ @Override
+ public List list(Wrapper queryWrapper) {
+ return getEntityList(queryWrapper);
+ }
@Override
public List getDepartmentSqlList(QueryWrapper queryWrapper, Pagination pagination) {
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/service/impl/StrIdTestServiceImpl.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/service/impl/StrIdTestServiceImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..eede0c2810761561d7442078ebee4aa4c34438d4
--- /dev/null
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/service/impl/StrIdTestServiceImpl.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2015-2020, www.dibo.ltd (service@dibo.ltd).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package diboot.core.test.binder.service.impl;
+
+import com.diboot.core.service.impl.BaseServiceImpl;
+import diboot.core.test.binder.entity.StrIdTest;
+import diboot.core.test.binder.mapper.StrIdTestMapper;
+import diboot.core.test.binder.service.StrIdTestService;
+import org.springframework.stereotype.Service;
+
+/**
+ * StrIdTest关Service
+ * @author mazc@dibo.ltd
+ * @version 2022/9/19
+ */
+@Service
+public class StrIdTestServiceImpl extends BaseServiceImpl implements StrIdTestService {
+
+}
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/CustomerVO.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/CustomerVO.java
new file mode 100644
index 0000000000000000000000000000000000000000..12918546d1f1c7b7bded89ddb613ae143ece4f56
--- /dev/null
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/CustomerVO.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2015-2020, www.dibo.ltd (service@dibo.ltd).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package diboot.core.test.binder.vo;
+
+import com.diboot.core.binding.annotation.BindDict;
+import diboot.core.test.binder.entity.Customer;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.experimental.Accessors;
+
+import java.util.List;
+
+/**
+ *
+ *
+ * @author mazc@dibo.ltd
+ * @version v2.0
+ * @date 2019/06/22
+ */
+@Getter
+@Setter
+@Accessors(chain = true)
+public class CustomerVO extends Customer {
+
+ @BindDict(type = "MESSAGE_CHANNEL", field = "extjsonarr")
+ private List channelLabels;
+
+}
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/DepartmentVO.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/DepartmentVO.java
index e98de17be12b3d5ab6adc611f773aa3af4079d0e..c2520664707e03e5c9db52c059d3fecd3724d1e0 100644
--- a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/DepartmentVO.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/DepartmentVO.java
@@ -54,7 +54,7 @@ public class DepartmentVO {
private Department department;
// 关联Entity,赋值给VO
- @BindEntity(entity = Organization.class, condition = "this.org_id=id") // AND ...
+ @BindEntity(entity = Organization.class, condition = "this.org_id=id", deepBind = true) // AND ...
private OrganizationVO organizationVO;
@BindEntityList(entity = Department.class, condition = "this.id=parent_id AND this.name IS NOT NULL") // AND ...
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/EntityBinderVO.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/EntityBinderVO.java
index ff1944b14251eed4fe40fe308081638034365e78..cac1c9f4a1fac49061a674f662b1e7ef63c20f67 100644
--- a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/EntityBinderVO.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/EntityBinderVO.java
@@ -34,7 +34,7 @@ import lombok.experimental.Accessors;
public class EntityBinderVO extends User {
private static final long serialVersionUID = 3526115343377985725L;
- // 字段关联,相同条件的entity+condition将合并为一条SQL查询
+ // 实体关联,支持附加条件
@BindEntity(entity= Department.class, condition="this.department_id=id AND name like '发'") // AND is_deleted=1
private Department department;
@@ -42,4 +42,8 @@ public class EntityBinderVO extends User {
@BindEntity(entity = Organization.class, condition = "this.department_id=department.id AND department.org_id=id AND parent_id=0") // AND ...
private OrganizationVO organizationVO;
+ // 实体关联
+ @BindEntity(entity= Department.class, condition="this.department_id=id") // AND is_deleted=1
+ private Department department2;
+
}
\ No newline at end of file
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/SimpleSplitVO.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/SimpleSplitVO.java
index 299817abab769dcbdc5782b16418c02a735cc8d5..fe1ca2c3463c5a42d2753e89ef2491e769ef2177 100644
--- a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/SimpleSplitVO.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/SimpleSplitVO.java
@@ -43,10 +43,17 @@ public class SimpleSplitVO extends Department {
//@BindEntityList(entity = User.class, condition="this.character=id", splitBy= Cons.SEPARATOR_COMMA)
private List managers;
-
// ,拆分的id值绑定
@BindFieldList(entity = User.class, field = "username", condition="this.`character`=id", splitBy= Cons.SEPARATOR_COMMA)
//@BindFieldList(entity = User.class, field = "username", condition="this.character=id", splitBy= Cons.SEPARATOR_COMMA)
private List managerNames;
+ // JsonArray的id值绑定
+ @BindEntityList(entity = User.class, condition="this.extjsonarr=id")
+ private List managersByJson;
+
+ // JSONArray的id值绑定
+ @BindFieldList(entity = User.class, field = "username", condition="this.extjsonarr=id")
+ private List managerNamesByJson;
+
}
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/UserExtVO.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/UserExtVO.java
index be86b4e4cfad65617e93d68a1ac3646d38b32b3b..a8b44aabe45839ecd475e5e489b2489ce054e069 100644
--- a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/UserExtVO.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/UserExtVO.java
@@ -17,11 +17,7 @@ package diboot.core.test.binder.vo;
import com.diboot.core.binding.annotation.BindField;
import com.diboot.core.binding.annotation.BindFieldList;
-import com.diboot.core.binding.query.BindQuery;
-import com.diboot.core.binding.query.Comparison;
-import com.diboot.core.binding.query.Strategy;
import diboot.core.test.binder.entity.Department;
-import diboot.core.test.binder.entity.Organization;
import diboot.core.test.binder.entity.Role;
import diboot.core.test.binder.entity.User;
import lombok.Getter;
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/UserJsonVO.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/UserJsonVO.java
new file mode 100644
index 0000000000000000000000000000000000000000..ef07d63fd25a319d22e491949efc653ff16abb18
--- /dev/null
+++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/UserJsonVO.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015-2020, www.dibo.ltd (service@dibo.ltd).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package diboot.core.test.binder.vo;
+
+import com.diboot.core.binding.annotation.BindEntityList;
+import com.diboot.core.binding.annotation.BindFieldList;
+import diboot.core.test.binder.entity.Department;
+import diboot.core.test.binder.entity.User;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.experimental.Accessors;
+
+import java.util.List;
+
+/**
+ *
+ *
+ * @author mazc@dibo.ltd
+ * @version v2.7.0
+ * @date 2022/09/09
+ */
+@Getter
+@Setter
+@Accessors(chain = true)
+public class UserJsonVO extends User {
+ private static final long serialVersionUID = 3526115343377985709L;
+
+ // 字段关联,附加更多条件
+ @BindFieldList(entity= Department.class, field="name", condition="this.id=extjsonarr")
+ private List deptNames;
+
+ // 字段关联,附加更多条件
+ @BindEntityList(entity= Department.class, condition="this.id=extjsonarr")
+ private List departments;
+
+}
\ No newline at end of file
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/config/SpringMvcConfig.java b/diboot-core-starter/src/test/java/diboot/core/test/config/SpringMvcConfig.java
index a6f5fc89ceff9fc16149ef205378a0db86c21fdd..36be126991585c1ec9ad18ddbb31622a2d69abbf 100644
--- a/diboot-core-starter/src/test/java/diboot/core/test/config/SpringMvcConfig.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/config/SpringMvcConfig.java
@@ -22,9 +22,7 @@ import com.diboot.core.handler.DataAccessControlInterceptor;
import com.diboot.core.util.ContextHelper;
import com.diboot.core.util.D;
import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
@@ -43,7 +41,6 @@ import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.format.FormatterRegistry;
-import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@@ -54,7 +51,6 @@ import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
-import java.util.List;
import java.util.TimeZone;
/***
@@ -145,6 +141,8 @@ public class SpringMvcConfig implements WebMvcConfigurer {
registry.addConverter(new Date2LocalDateConverter());
registry.addConverter(new Date2LocalDateTimeConverter());
registry.addConverter(new String2DateConverter());
+ registry.addConverter(new String2LocalDateConverter());
+ registry.addConverter(new String2LocalDateTimeConverter());
registry.addConverter(new String2BooleanConverter());
registry.addConverter(new Timestamp2LocalDateTimeConverter());
}
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java b/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java
index 4f1ffde54f5094f62e1a7d8262a5187d26a487a5..e60bb362d8cefda33b1d5d943f2359b49b5fdba5 100644
--- a/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java
@@ -19,14 +19,17 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diboot.core.binding.Binder;
import com.diboot.core.binding.JoinsBinder;
import com.diboot.core.binding.QueryBuilder;
+import com.diboot.core.binding.query.dynamic.ExtQueryWrapper;
import com.diboot.core.config.Cons;
import com.diboot.core.vo.Pagination;
import diboot.core.test.StartupApplication;
import diboot.core.test.binder.dto.DepartmentDTO;
import diboot.core.test.binder.dto.UserDTO;
import diboot.core.test.binder.entity.Department;
+import diboot.core.test.binder.entity.StrIdTest;
import diboot.core.test.binder.entity.User;
import diboot.core.test.binder.service.DepartmentService;
+import diboot.core.test.binder.service.StrIdTestService;
import diboot.core.test.binder.service.UserService;
import diboot.core.test.binder.vo.DepartmentVO;
import diboot.core.test.config.SpringMvcConfig;
@@ -60,6 +63,9 @@ public class TestJoinQuery {
@Autowired
UserService userService;
+ @Autowired
+ StrIdTestService strIdTestService;
+
@Test
public void testDateCompaire(){
Department example = departmentService.list(null).get(0);
@@ -85,6 +91,7 @@ public class TestJoinQuery {
queryWrapper = QueryBuilder.toQueryWrapper(departmentDTO);
list = Binder.joinQueryList(queryWrapper, Department.class);
Assert.assertTrue(list.size() > 0);
+
}
@Test
@@ -118,6 +125,11 @@ public class TestJoinQuery {
public void testDynamicSqlQuery(){
// 初始化DTO,测试不涉及关联的情况
DepartmentDTO dto = new DepartmentDTO();
+ //dto.setOrgName("");
+ ExtQueryWrapper query = QueryBuilder.toDynamicJoinQueryWrapper(dto);
+ List departmentList = query.queryList(Department.class);
+ Assert.assertTrue(departmentList.size() > 3);
+
dto.setParentId(10001L);
// 验证 转换后的wrapper可以直接查询
@@ -132,12 +144,9 @@ public class TestJoinQuery {
List builderResultList = QueryBuilder.toDynamicJoinQueryWrapper(dto).queryList(Department.class);
Assert.assertTrue(builderResultList.size() == 3);
- // 初始化DTO
- dto = new DepartmentDTO();
dto.setParentId(10001L);
- dto.setParentName("产品部");
- //boolean类型
dto.setOrgName("苏州帝博");
+ dto.setParentName("产品部");
// 验证直接查询指定字段
List fields = Arrays.asList("parentId", "parentName", "orgName");
@@ -156,6 +165,9 @@ public class TestJoinQuery {
// 不分页 3条结果
List list = JoinsBinder.queryList(queryWrapper, Department.class);
Assert.assertTrue(list.size() == 3);
+ Department departmentFirst = departmentService.getSingleEntity(queryWrapper);
+ Assert.assertTrue(departmentFirst.getId().equals(list.get(0).getId()));
+
// 不分页,直接用wrapper查
list = QueryBuilder.toDynamicJoinQueryWrapper(dto).queryList(Department.class);
Assert.assertTrue(list.size() == 3);
@@ -181,6 +193,8 @@ public class TestJoinQuery {
// 第二页 1条结果
list = Binder.joinQueryList(queryWrapper, Department.class, pagination);
Assert.assertTrue(list.size() == 1);
+
+
}
/**
@@ -229,6 +243,44 @@ public class TestJoinQuery {
Assert.assertTrue(userList.size() > 0);
}
+ @Test
+ public void testDynamicSqlQueryWithOrders(){
+ // 初始化DTO,测试不涉及关联的情况
+ DepartmentDTO dto = new DepartmentDTO();
+ dto.setParentId(10001L);
+ dto.setOrgName("苏州");
+
+ // 分页
+ Pagination pagination = new Pagination();
+ pagination.setPageSize(2);
+ pagination.setPageIndex(1);
+ // 测试排序
+ pagination.setOrderBy("orgName:DESC,parentName");
+
+ // 验证 转换后的wrapper可以直接查询
+ QueryWrapper queryWrapper = QueryBuilder.toDynamicJoinQueryWrapper(dto, pagination);
+ // 第二页 1条结果
+ List departments = departmentService.getEntityList(queryWrapper, pagination);
+ Assert.assertTrue(departments.size() == pagination.getPageSize());
+ }
+
+ @Test
+ public void testIgnoreEmptyDynamicSqlQuery(){
+ // 初始化DTO,测试不涉及关联的情况
+ DepartmentDTO dto = new DepartmentDTO();
+ // builder直接查询,不分页 3条结果
+ List builderResultList = departmentService.getEntityList(QueryBuilder.toQueryWrapper(dto));
+ Assert.assertTrue(builderResultList.size() == 6);
+
+ dto.setName("");
+ builderResultList = departmentService.getEntityList(QueryBuilder.toQueryWrapper(dto));
+ Assert.assertTrue(builderResultList.size() == 6);
+
+ dto.setOrgName("");
+ builderResultList = departmentService.getEntityList(QueryBuilder.toQueryWrapper(dto));
+ Assert.assertTrue(builderResultList.size() == 6);
+ }
+
@Test
public void testBindQueryGroup(){
DepartmentDTO departmentDTO = new DepartmentDTO();
@@ -272,6 +324,17 @@ public class TestJoinQuery {
Assert.assertTrue(sql.contains("LIMIT 1"));
}
+ @Test
+ public void testStringIdBuildQuery(){
+ StrIdTest strIdTest = new StrIdTest();
+ strIdTest.setId("123");
+ strIdTest.setType("A");
+ QueryWrapper queryWrapper = QueryBuilder.toDynamicJoinQueryWrapper(strIdTest);
+ String sql = queryWrapper.getExpression().getSqlSegment();
+ System.out.println(sql);
+ Assert.assertTrue(sql.contains("ID_ ="));
+ }
+
/**
* 构建检测是否有删除字段的sql
* @param middleTable
diff --git a/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java b/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java
index d44bccc7d40b6ec3459b3a707b06302fafa9185e..e94bb7e7de5af8385982eea7ec9ac9ddab1f2e0a 100644
--- a/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java
+++ b/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java
@@ -25,19 +25,20 @@ import com.diboot.core.binding.QueryBuilder;
import com.diboot.core.binding.RelationsBinder;
import com.diboot.core.binding.cache.BindingCacheManager;
import com.diboot.core.binding.parser.EntityInfoCache;
+import com.diboot.core.binding.query.dynamic.ExtQueryWrapper;
import com.diboot.core.config.BaseConfig;
import com.diboot.core.data.access.DataAccessInterface;
import com.diboot.core.entity.Dictionary;
import com.diboot.core.service.impl.DictionaryServiceExtImpl;
import com.diboot.core.util.*;
import com.diboot.core.vo.*;
+import com.fasterxml.jackson.core.type.TypeReference;
import diboot.core.test.StartupApplication;
-import diboot.core.test.binder.entity.CcCityInfo;
-import diboot.core.test.binder.entity.Department;
-import diboot.core.test.binder.entity.User;
-import diboot.core.test.binder.entity.UserRole;
+import diboot.core.test.binder.dto.UserDTO;
+import diboot.core.test.binder.entity.*;
import diboot.core.test.binder.service.CcCityInfoService;
import diboot.core.test.binder.service.DepartmentService;
+import diboot.core.test.binder.service.OrganizationService;
import diboot.core.test.binder.service.UserService;
import diboot.core.test.binder.vo.SimpleDictionaryVO;
import diboot.core.test.config.SpringMvcConfig;
@@ -46,6 +47,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
@@ -72,6 +74,12 @@ public class BaseServiceTest {
@Autowired
DepartmentService departmentService;
+ @Autowired
+ JdbcTemplate jdbcTemplate;
+
+ @Autowired
+ OrganizationService organizationService;
+
@Test
public void testGet(){
// 查询总数
@@ -193,9 +201,20 @@ public class BaseServiceTest {
IPage dictionaryPage = dictionaryService.page(dp, queryWrapper);
- PagingJsonResult pagingJsonResult = new PagingJsonResult(dictionaryPage);
+ PagingJsonResult pagingJsonResult = new JsonResult().data(dictionaryPage.getRecords()).bindPagination(new Pagination());
Assert.assertTrue(V.notEmpty(pagingJsonResult));
Assert.assertTrue(pagingJsonResult.getPage().getOrderBy().equals("id:DESC"));
+
+ PagingJsonResult> pagingJsonResult2 = new PagingJsonResult(dictionaryPage);
+ String jsonStr = JSON.stringify(pagingJsonResult2);
+ System.out.println(jsonStr);
+ Assert.assertTrue(pagingJsonResult2.getPage().getOrderBy().equals("id:DESC"));
+
+ PagingJsonResult> pagingJsonResult3 = JSON.parseObject(jsonStr,
+ new TypeReference>>() {}
+ );
+ Assert.assertTrue(pagingJsonResult3.getPage() != null);
+ Assert.assertTrue(pagingJsonResult3.getData() != null);
}
/**
@@ -319,6 +338,22 @@ public class BaseServiceTest {
String val = dictionaryService.getValueOfField(Dictionary::getId, 2L, Dictionary::getItemValue);
Assert.assertTrue("M".equals(val));
System.out.println(val);
+
+ // 初始化DTO,测试不涉及关联的情况
+ UserDTO dto = new UserDTO();
+ dto.setUsername("张三");
+ // builder直接查询,不分页 3条结果
+ ExtQueryWrapper queryWrapper = QueryBuilder.toDynamicJoinQueryWrapper(dto);
+ List values = userService.getValuesOfField(queryWrapper, User::getUsername);
+ Assert.assertTrue(values.size() == 1);
+ dto.setUsername(null);
+
+ dto.setDeptId(10002L);
+ dto.setDeptName("研发组");
+ dto.setOrgName("苏州帝博");
+ queryWrapper = QueryBuilder.toDynamicJoinQueryWrapper(dto);
+ List values2 = userService.getValuesOfField(queryWrapper, User::getUsername);
+ Assert.assertTrue(values2.size() == 2);
}
@Test
@@ -353,6 +388,12 @@ public class BaseServiceTest {
pagination.setPageIndex(2);
voList = dictionaryService.getViewObjectList(queryWrapper, pagination, DictionaryVO.class);
Assert.assertTrue(voList.size() == 1);
+
+ // 测试 ORDER BY name
+ pagination = new Pagination();
+ pagination.setOrderBy("name:DESC");
+ List organizations = organizationService.getEntityList(null, pagination);
+ Assert.assertTrue(organizations != null && organizations.get(0).getName().contains("苏州帝博"));
}
@Test
@@ -508,4 +549,29 @@ public class BaseServiceTest {
//ContextHelper.getBean(CcCityInfoService.class).removeById(cityInfo.getId());
}
+ @Test
+ public void testJdbcTemplate(){
+ List