binder增加单对象绑定接口
This commit is contained in:
parent
4bf89f5989
commit
95ed4ebbaf
|
@ -38,9 +38,24 @@ public class RelationsBinder {
|
|||
private static final Logger log = LoggerFactory.getLogger(RelationsBinder.class);
|
||||
|
||||
/**
|
||||
* 自动转换和绑定VO中的注解关联
|
||||
* @param entityList
|
||||
* @param voClass
|
||||
* 自动转换和绑定单个VO中的注解关联(禁止循环调用,多个对象请调用convertAndBind(voList, voClass))
|
||||
* @param voClass 需要转换的VO class
|
||||
* @param <E>
|
||||
* @param <VO>
|
||||
* @return
|
||||
*/
|
||||
public static <E, VO> VO convertAndBind(E entity, Class<VO> voClass){
|
||||
// 转换为VO列表
|
||||
VO vo = BeanUtils.convert(entity, voClass);
|
||||
// 自动绑定关联对象
|
||||
bind(vo);
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动转换和绑定多个VO中的注解关联
|
||||
* @param entityList 需要转换的VO list
|
||||
* @param voClass VO class
|
||||
* @param <E>
|
||||
* @param <VO>
|
||||
* @return
|
||||
|
@ -54,7 +69,20 @@ public class RelationsBinder {
|
|||
}
|
||||
|
||||
/**
|
||||
* 自动绑定关联对象
|
||||
* 自动绑定单个VO的关联对象(禁止循环调用,多个对象请调用bind(voList))
|
||||
* @param vo 需要注解绑定的对象
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static <VO> void bind(VO vo){
|
||||
List<VO> voList = new ArrayList<>(1);
|
||||
voList.add(vo);
|
||||
bind(voList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动绑定多个VO集合的关联对象
|
||||
* @param voList 需要注解绑定的对象集合
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
|
|
|
@ -2,6 +2,7 @@ package diboot.core.test.binder;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.diboot.core.binding.RelationsBinder;
|
||||
import com.diboot.core.util.BeanUtils;
|
||||
import com.diboot.core.util.JSON;
|
||||
import com.diboot.core.util.V;
|
||||
import diboot.core.test.StartupApplication;
|
||||
|
@ -52,6 +53,16 @@ public class TestEntityBinder {
|
|||
System.out.println(JSON.stringify(vo.getOrganizationVO()));
|
||||
System.out.println(JSON.stringify(vo));
|
||||
}
|
||||
// 单个entity接口测试
|
||||
EntityBinderVO singleVO = BeanUtils.convert(userList.get(0), EntityBinderVO.class);
|
||||
RelationsBinder.bind(singleVO);
|
||||
// 验证直接关联和通过中间表间接关联的绑定
|
||||
Assert.assertEquals(singleVO.getDepartmentId(), singleVO.getDepartment().getId());
|
||||
Assert.assertNotNull(singleVO.getDepartment().getOrgId());
|
||||
// 测试绑定VO
|
||||
Assert.assertNotNull(singleVO.getOrganizationVO());
|
||||
System.out.println(JSON.stringify(singleVO.getOrganizationVO()));
|
||||
System.out.println(JSON.stringify(singleVO));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue