mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
test: 测试集合子类型的支持。
This commit is contained in:
parent
14a7af8f89
commit
f47d064732
@ -26,7 +26,7 @@ import com.mybatisflex.annotation.Table;
|
||||
* @since 2023-06-07
|
||||
*/
|
||||
@Table("tb_role")
|
||||
public class Role {
|
||||
public class Role implements Comparable<Role> {
|
||||
|
||||
@Id
|
||||
private Integer roleId;
|
||||
@ -65,4 +65,9 @@ public class Role {
|
||||
", roleName='" + roleName + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Role o) {
|
||||
return Integer.compare(this.roleId, o.roleId);
|
||||
}
|
||||
}
|
||||
@ -16,7 +16,8 @@
|
||||
|
||||
package com.mybatisflex.test.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* 用户 VO 对象。
|
||||
@ -29,7 +30,7 @@ public class UserVO {
|
||||
|
||||
private String userId;
|
||||
private String userName;
|
||||
private List<Role> roleList;
|
||||
private TreeSet<Role> roleList;
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
@ -47,11 +48,11 @@ public class UserVO {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public List<Role> getRoleList() {
|
||||
public Collection<Role> getRoleList() {
|
||||
return roleList;
|
||||
}
|
||||
|
||||
public void setRoleList(List<Role> roleList) {
|
||||
public void setRoleList(TreeSet<Role> roleList) {
|
||||
this.roleList = roleList;
|
||||
}
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.mybatisflex.core.query.QueryMethods.select;
|
||||
import static com.mybatisflex.test.model.table.GoodTableDef.GOOD;
|
||||
import static com.mybatisflex.test.model.table.OrderGoodTableDef.ORDER_GOOD;
|
||||
import static com.mybatisflex.test.model.table.OrderTableDef.ORDER;
|
||||
@ -59,6 +60,31 @@ class UserMapperTest {
|
||||
System.err.println(userVO);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFieldQuery() {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(USER.USER_ID, USER.USER_NAME)
|
||||
.from(USER.as("u"))
|
||||
.where(USER.USER_ID.eq(3));
|
||||
System.out.println(queryWrapper.toSQL());
|
||||
List<UserVO> userVOs = userMapper.selectListByQueryAs(queryWrapper, UserVO.class,
|
||||
fieldQueryBuilder -> fieldQueryBuilder
|
||||
.field(UserVO::getRoleList)
|
||||
.queryWrapper(user -> QueryWrapper.create()
|
||||
.select()
|
||||
.from(ROLE)
|
||||
.where(ROLE.ROLE_ID.in(
|
||||
select(USER_ROLE.ROLE_ID)
|
||||
.from(USER_ROLE)
|
||||
.where(USER_ROLE.USER_ID.eq(user.getUserId())
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
System.err.println(userVOs);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSelectList() {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
@ -66,12 +92,9 @@ class UserMapperTest {
|
||||
.from(USER.as("u"))
|
||||
.leftJoin(USER_ROLE).as("ur").on(USER_ROLE.USER_ID.eq(USER.USER_ID))
|
||||
.leftJoin(ROLE).as("r").on(USER_ROLE.ROLE_ID.eq(ROLE.ROLE_ID))
|
||||
.where(USER.USER_ID.ge(2));
|
||||
.where(USER.USER_ID.eq(3));
|
||||
System.out.println(queryWrapper.toSQL());
|
||||
List<UserVO> userVOS = userMapper.selectListByQueryAs(queryWrapper, UserVO.class);
|
||||
// List<UserVO1> userVOS = userMapper.selectListByQueryAs(queryWrapper, UserVO1.class);
|
||||
// List<UserVO2> userVOS = userMapper.selectListByQueryAs(queryWrapper, UserVO2.class);
|
||||
// List<UserVO3> userVOS = userMapper.selectListByQueryAs(queryWrapper, UserVO3.class);
|
||||
userVOS.forEach(System.err::println);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user