+ fix: 绑定注解的condition中有等于字符串附加条件时执行异常的问题
This commit is contained in:
parent
518ac43623
commit
9b962e91d9
|
@ -39,7 +39,7 @@ subprojects {
|
|||
mysqlConnectorVersion = "8.0.16"
|
||||
mybatisStarterVersion = "2.1.0"
|
||||
mybatisPlusVersion = "3.2.0"
|
||||
fastjsonVersion = "1.2.60"
|
||||
fastjsonVersion = "1.2.62"
|
||||
lombokVersion = "1.18.8"
|
||||
validatorVersion = "6.0.17.Final"
|
||||
}
|
||||
|
|
|
@ -77,27 +77,27 @@ public abstract class BaseBinder<T> {
|
|||
}
|
||||
|
||||
public BaseBinder<T> andEQ(String fieldName, Object value){
|
||||
queryWrapper.eq(S.toSnakeCase(fieldName), value);
|
||||
queryWrapper.eq(S.toSnakeCase(fieldName), formatValue(value));
|
||||
return this;
|
||||
}
|
||||
public BaseBinder<T> andNE(String fieldName, Object value){
|
||||
queryWrapper.ne(S.toSnakeCase(fieldName), value);
|
||||
queryWrapper.ne(S.toSnakeCase(fieldName), formatValue(value));
|
||||
return this;
|
||||
}
|
||||
public BaseBinder<T> andGT(String fieldName, Object value){
|
||||
queryWrapper.gt(S.toSnakeCase(fieldName), value);
|
||||
queryWrapper.gt(S.toSnakeCase(fieldName), formatValue(value));
|
||||
return this;
|
||||
}
|
||||
public BaseBinder<T> andGE(String fieldName, Object value){
|
||||
queryWrapper.ge(S.toSnakeCase(fieldName), value);
|
||||
queryWrapper.ge(S.toSnakeCase(fieldName), formatValue(value));
|
||||
return this;
|
||||
}
|
||||
public BaseBinder<T> andLT(String fieldName, Object value){
|
||||
queryWrapper.lt(S.toSnakeCase(fieldName), value);
|
||||
queryWrapper.lt(S.toSnakeCase(fieldName), formatValue(value));
|
||||
return this;
|
||||
}
|
||||
public BaseBinder<T> andLE(String fieldName, Object value){
|
||||
queryWrapper.le(S.toSnakeCase(fieldName), value);
|
||||
queryWrapper.le(S.toSnakeCase(fieldName), formatValue(value));
|
||||
return this;
|
||||
}
|
||||
public BaseBinder<T> andIsNotNull(String fieldName){
|
||||
|
@ -109,11 +109,11 @@ public abstract class BaseBinder<T> {
|
|||
return this;
|
||||
}
|
||||
public BaseBinder<T> andBetween(String fieldName, Object begin, Object end){
|
||||
queryWrapper.between(S.toSnakeCase(fieldName), begin, end);
|
||||
queryWrapper.between(S.toSnakeCase(fieldName), formatValue(begin), formatValue(end));
|
||||
return this;
|
||||
}
|
||||
public BaseBinder<T> andLike(String fieldName, String value){
|
||||
queryWrapper.like(S.toSnakeCase(fieldName), value);
|
||||
queryWrapper.like(S.toSnakeCase(fieldName), formatValue(value));
|
||||
return this;
|
||||
}
|
||||
public BaseBinder<T> andIn(String fieldName, Collection valueList){
|
||||
|
@ -125,11 +125,11 @@ public abstract class BaseBinder<T> {
|
|||
return this;
|
||||
}
|
||||
public BaseBinder<T> andNotBetween(String fieldName, Object begin, Object end){
|
||||
queryWrapper.notBetween(S.toSnakeCase(fieldName), begin, end);
|
||||
queryWrapper.notBetween(S.toSnakeCase(fieldName), formatValue(begin), formatValue(end));
|
||||
return this;
|
||||
}
|
||||
public BaseBinder<T> andNotLike(String fieldName, String value){
|
||||
queryWrapper.notLike(S.toSnakeCase(fieldName), value);
|
||||
queryWrapper.notLike(S.toSnakeCase(fieldName), formatValue(value));
|
||||
return this;
|
||||
}
|
||||
public BaseBinder<T> andApply(String applySql){
|
||||
|
@ -190,4 +190,16 @@ public abstract class BaseBinder<T> {
|
|||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化条件值
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
private Object formatValue(Object value){
|
||||
if(value instanceof String && S.contains((String)value, "'")){
|
||||
value = S.replace((String)value, "'", "");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@ import java.util.Map;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 加解密工具类 (提供AES加解密,MD5多次哈希...)
|
||||
* 加解密工具类 (提供AES加解密)
|
||||
* @author Mazhicheng
|
||||
* @version v2.0
|
||||
* @date 2019/01/01
|
||||
|
|
|
@ -5,9 +5,12 @@ import com.diboot.core.binding.RelationsBinder;
|
|||
import com.diboot.core.util.JSON;
|
||||
import com.diboot.core.util.V;
|
||||
import diboot.core.test.StartupApplication;
|
||||
import diboot.core.test.binder.entity.Department;
|
||||
import diboot.core.test.binder.entity.User;
|
||||
import diboot.core.test.binder.service.DepartmentService;
|
||||
import diboot.core.test.binder.service.UserService;
|
||||
import diboot.core.test.binder.vo.FieldBinderVO;
|
||||
import diboot.core.test.binder.vo.UserVO;
|
||||
import diboot.core.test.config.SpringMvcConfig;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -32,6 +35,8 @@ public class TestFieldBinder {
|
|||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
@Autowired
|
||||
DepartmentService departmentService;
|
||||
|
||||
@Test
|
||||
public void testBinder(){
|
||||
|
@ -56,4 +61,19 @@ public class TestFieldBinder {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBinderWithMoreCondition(){
|
||||
// 加载测试数据
|
||||
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(User::getId, 1001L, 1002L);
|
||||
List<User> userList = userService.list(queryWrapper);
|
||||
// 自动绑定
|
||||
List<UserVO> voList = RelationsBinder.convertAndBind(userList, UserVO.class);
|
||||
if(V.notEmpty(voList)){
|
||||
for(UserVO vo : voList){
|
||||
Assert.assertNotNull(vo.getDeptName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,8 +15,18 @@ import java.util.List;
|
|||
*/
|
||||
public class EntityListComplexBinderVO extends User {
|
||||
|
||||
private String userType = "OrgUser";
|
||||
|
||||
public String getUserType() {
|
||||
return userType;
|
||||
}
|
||||
|
||||
public void setUserType(String userType) {
|
||||
this.userType = userType;
|
||||
}
|
||||
|
||||
// 支持通过中间表的多-多Entity实体关联
|
||||
@BindEntityList(entity = Role.class, condition="this.id=user_role.user_id AND user_role.role_id=id")
|
||||
@BindEntityList(entity = Role.class, condition="this.id=user_role.user_id AND user_role.role_id=id") // AND user_role.user_type=this.user_type AND user_role.is_deleted=0
|
||||
private List<Role> roleList;
|
||||
|
||||
public List<Role> getRoleList() {
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package diboot.core.test.binder.vo;
|
||||
|
||||
import com.diboot.core.binding.annotation.BindDict;
|
||||
import com.diboot.core.binding.annotation.BindField;
|
||||
import diboot.core.test.binder.entity.Department;
|
||||
import diboot.core.test.binder.entity.Organization;
|
||||
import diboot.core.test.binder.entity.User;
|
||||
|
||||
/**
|
||||
* <Description>
|
||||
*
|
||||
* @author Mazhicheng
|
||||
* @version v2.0
|
||||
* @date 2019/06/22
|
||||
*/
|
||||
public class UserVO extends User{
|
||||
private static final long serialVersionUID = 3526115343377985709L;
|
||||
|
||||
// 字段关联,附加更多条件
|
||||
@BindField(entity= Department.class, field="name", condition="this.department_id=id AND parent_id IS NOT NULL AND name = '研发组'")
|
||||
private String deptName;
|
||||
|
||||
public String getDeptName() {
|
||||
return deptName;
|
||||
}
|
||||
public void setDeptName(String deptName) {
|
||||
this.deptName = deptName;
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@ spring.datasource.hikari.driver-class-name=com.mysql.cj.jdbc.Driver
|
|||
|
||||
# logging config
|
||||
logging.pattern.console=%clr{%d{MM-dd HH:mm:ss.SSS}}{faint} %clr{%5p} %clr{${PID}}{faint} %clr{---}{faint} %clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n%xwEx
|
||||
logging.level.root=info
|
||||
logging.level.root=debug
|
||||
logging.level.org.apache=info
|
||||
logging.level.org.hibernate.validator=info
|
||||
logging.level.org.springframework=info
|
||||
|
|
Loading…
Reference in New Issue