Search in sources :

Example 1 with UserVO

use of diboot.core.test.binder.vo.UserVO in project diboot by dibo-software.

the class TestDictBinder method testBinder.

@Test
public void testBinder() {
    // 加载测试数据
    LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.in(User::getId, 1001L, 1002L);
    List<User> userList = userService.getEntityList(queryWrapper);
    // 自动绑定
    List<UserVO> voList = Binder.convertAndBindRelations(userList, UserVO.class);
    // 验证绑定结果
    Assert.assertTrue(V.notEmpty(voList));
    for (UserVO vo : voList) {
        // 验证直接关联和通过中间表间接关联的绑定
        Assert.assertNotNull(vo.getGenderLabel());
        System.out.println(JSON.stringify(vo));
    }
    // 单个entity接口测试
    UserVO singleVO = BeanUtils.convert(userList.get(1), UserVO.class);
    Binder.bindRelations(singleVO);
    // 验证直接关联和通过中间表间接关联的绑定
    Assert.assertNotNull(singleVO.getGenderLabel());
    System.out.println(JSON.stringify(singleVO));
}
Also used : User(diboot.core.test.binder.entity.User) UserVO(diboot.core.test.binder.vo.UserVO) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 User (diboot.core.test.binder.entity.User)1 UserVO (diboot.core.test.binder.vo.UserVO)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1