mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
test: 更新测试。
This commit is contained in:
parent
d867a2671c
commit
3575c6894b
@ -117,7 +117,8 @@ public class AccountTester {
|
||||
Account account = new Account();
|
||||
account.setId(4L);
|
||||
account.setUserName("test04");
|
||||
accountMapper.insertSelectiveWithPk(account);
|
||||
int rows = accountMapper.insertSelectiveWithPk(account);
|
||||
System.out.println(rows);
|
||||
|
||||
accounts = accountMapper.selectAll();
|
||||
System.out.println(accounts);
|
||||
|
||||
@ -16,11 +16,9 @@
|
||||
|
||||
package com.mybatisflex.test.model;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.RelationManyToMany;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 用户信息。
|
||||
@ -33,7 +31,6 @@ public class UserInfo {
|
||||
private Integer userId;
|
||||
private String userName;
|
||||
private String password;
|
||||
@Column(ignore = true)
|
||||
private String idNumber;
|
||||
|
||||
@RelationManyToMany(
|
||||
@ -115,44 +112,4 @@ public class UserInfo {
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
UserInfo userInfo = (UserInfo) o;
|
||||
|
||||
if (!Objects.equals(userId, userInfo.userId)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(userName, userInfo.userName)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(password, userInfo.password)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(idNumber, userInfo.idNumber)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(roleList, userInfo.roleList)) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(orderInfoList, userInfo.orderInfoList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = userId != null ? userId.hashCode() : 0;
|
||||
result = 31 * result + (userName != null ? userName.hashCode() : 0);
|
||||
result = 31 * result + (password != null ? password.hashCode() : 0);
|
||||
result = 31 * result + (idNumber != null ? idNumber.hashCode() : 0);
|
||||
result = 31 * result + (roleList != null ? roleList.hashCode() : 0);
|
||||
result = 31 * result + (orderInfoList != null ? orderInfoList.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -16,8 +16,8 @@
|
||||
|
||||
package com.mybatisflex.test.model;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.TreeSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户 VO 对象。
|
||||
@ -30,7 +30,9 @@ public class UserVO {
|
||||
|
||||
private String userId;
|
||||
private String userName;
|
||||
private TreeSet<Role> roleList;
|
||||
// private TreeSet<Role> roleList;
|
||||
// private Role[] roleList;
|
||||
private HashMap<String, Object> roleList;
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
@ -48,11 +50,11 @@ public class UserVO {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public Collection<Role> getRoleList() {
|
||||
public Map<String, Object> getRoleList() {
|
||||
return roleList;
|
||||
}
|
||||
|
||||
public void setRoleList(TreeSet<Role> roleList) {
|
||||
public void setRoleList(HashMap<String, Object> roleList) {
|
||||
this.roleList = roleList;
|
||||
}
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
|
||||
package com.mybatisflex.test.mapper;
|
||||
|
||||
import com.mybatisflex.core.field.FieldType;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.test.model.*;
|
||||
@ -73,6 +74,7 @@ class UserMapperTest {
|
||||
List<UserVO> userVOs = userMapper.selectListByQueryAs(queryWrapper, UserVO.class,
|
||||
fieldQueryBuilder -> fieldQueryBuilder
|
||||
.field(UserVO::getRoleList)
|
||||
.prevent(true)
|
||||
.queryWrapper(user -> QueryWrapper.create()
|
||||
.select()
|
||||
.from(ROLE)
|
||||
@ -136,6 +138,40 @@ class UserMapperTest {
|
||||
userInfos.forEach(System.err::println);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testComplexSelectListFields() {
|
||||
List<UserInfo> userInfos = userMapper.selectListByQueryAs(QueryWrapper.create(), UserInfo.class,
|
||||
c -> c.field(UserInfo::getIdNumber).fieldType(FieldType.BASIC).queryWrapper(userInfo ->
|
||||
QueryWrapper.create()
|
||||
.select(ID_CARD.ID_NUMBER)
|
||||
.from(ID_CARD)
|
||||
.where(ID_CARD.ID.eq(userInfo.getUserId()))
|
||||
),
|
||||
c -> c.field(UserInfo::getRoleList).prevent().queryWrapper(userInfo ->
|
||||
QueryWrapper.create()
|
||||
.select()
|
||||
.from(ROLE.as("r"))
|
||||
.leftJoin(USER_ROLE).as("ur").on(USER_ROLE.ROLE_ID.eq(ROLE.ROLE_ID))
|
||||
.where(USER_ROLE.USER_ID.eq(userInfo.getUserId()))
|
||||
),
|
||||
c -> c.field(UserInfo::getOrderInfoList).queryWrapper(userInfo ->
|
||||
QueryWrapper.create()
|
||||
.select()
|
||||
.from(ORDER.as("o"))
|
||||
.leftJoin(USER_ORDER).as("uo").on(USER_ORDER.ORDER_ID.eq(ORDER.ORDER_ID))
|
||||
.where(USER_ORDER.USER_ID.eq(userInfo.getUserId()))
|
||||
),
|
||||
c -> c.nestedField(OrderInfo::getGoodList).prevent().queryWrapper(orderInfo ->
|
||||
QueryWrapper.create()
|
||||
.select()
|
||||
.from(GOOD.as("g"))
|
||||
.leftJoin(ORDER_GOOD).as("og").on(ORDER_GOOD.GOOD_ID.eq(GOOD.GOOD_ID))
|
||||
.where(ORDER_GOOD.ORDER_ID.eq(orderInfo.getOrderId()))
|
||||
)
|
||||
);
|
||||
userInfos.forEach(System.err::println);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEquals() {
|
||||
QueryWrapper queryWrapper1 = QueryWrapper.create()
|
||||
@ -150,16 +186,48 @@ class UserMapperTest {
|
||||
.leftJoin(GOOD).as("g").on(GOOD.GOOD_ID.eq(ORDER_GOOD.GOOD_ID))
|
||||
.orderBy(USER.USER_ID.asc(), ROLE.ROLE_ID.asc(), ORDER.ORDER_ID.asc(), GOOD.GOOD_ID.asc());
|
||||
List<UserInfo> userInfos1 = userMapper.selectListByQueryAs(queryWrapper1, UserInfo.class);
|
||||
userInfos1.forEach(System.err::println);
|
||||
|
||||
QueryWrapper queryWrapper2 = QueryWrapper.create()
|
||||
.select(USER.ALL_COLUMNS, ID_CARD.ID_NUMBER)
|
||||
.from(USER.as("u"))
|
||||
.leftJoin(ID_CARD).as("i").on(USER.USER_ID.eq(ID_CARD.ID));
|
||||
List<UserInfo> userInfos2 = userMapper.selectListWithRelationsByQueryAs(queryWrapper2, UserInfo.class);
|
||||
userInfos2.forEach(System.err::println);
|
||||
|
||||
Assertions.assertEquals(userInfos1, userInfos2);
|
||||
List<UserInfo> userInfos3 = userMapper.selectListByQueryAs(QueryWrapper.create(), UserInfo.class,
|
||||
c -> c.field(UserInfo::getIdNumber).fieldType(FieldType.BASIC).queryWrapper(userInfo ->
|
||||
QueryWrapper.create()
|
||||
.select(ID_CARD.ID_NUMBER)
|
||||
.from(ID_CARD)
|
||||
.where(ID_CARD.ID.eq(userInfo.getUserId()))
|
||||
),
|
||||
c -> c.field(UserInfo::getRoleList).prevent().queryWrapper(userInfo ->
|
||||
QueryWrapper.create()
|
||||
.select()
|
||||
.from(ROLE.as("r"))
|
||||
.leftJoin(USER_ROLE).as("ur").on(USER_ROLE.ROLE_ID.eq(ROLE.ROLE_ID))
|
||||
.where(USER_ROLE.USER_ID.eq(userInfo.getUserId()))
|
||||
.orderBy(ROLE.ROLE_ID.asc())
|
||||
),
|
||||
c -> c.field(UserInfo::getOrderInfoList).queryWrapper(userInfo ->
|
||||
QueryWrapper.create()
|
||||
.select()
|
||||
.from(ORDER.as("o"))
|
||||
.leftJoin(USER_ORDER).as("uo").on(USER_ORDER.ORDER_ID.eq(ORDER.ORDER_ID))
|
||||
.where(USER_ORDER.USER_ID.eq(userInfo.getUserId()))
|
||||
.orderBy(ORDER.ORDER_ID.asc())
|
||||
),
|
||||
c -> c.nestedField(OrderInfo::getGoodList).prevent().queryWrapper(orderInfo ->
|
||||
QueryWrapper.create()
|
||||
.select()
|
||||
.from(GOOD.as("g"))
|
||||
.leftJoin(ORDER_GOOD).as("og").on(ORDER_GOOD.GOOD_ID.eq(GOOD.GOOD_ID))
|
||||
.where(ORDER_GOOD.ORDER_ID.eq(orderInfo.getOrderId()))
|
||||
.orderBy(GOOD.GOOD_ID.asc())
|
||||
)
|
||||
);
|
||||
|
||||
Assertions.assertEquals(userInfos1.toString(), userInfos2.toString());
|
||||
Assertions.assertEquals(userInfos1.toString(), userInfos3.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user