test: 测试 VO 类重名映射。

This commit is contained in:
Suomm 2024-04-02 10:54:56 +08:00
parent 3b90960156
commit 4530bbb95f
4 changed files with 254 additions and 6 deletions

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.test.alisa;
import com.mybatisflex.annotation.ViewObject;
/**
* 部门
*
* @author 王帅
* @since 2023-11-16
*/
@ViewObject(ref = SysDept.class)
public class DeptVO extends BaseEntity {
private Integer id;
private String deptName;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getDeptName() {
return deptName;
}
public void setDeptName(String deptName) {
this.deptName = deptName;
}
@Override
public String toString() {
return "SysDept{" +
"id=" + id +
", deptName='" + deptName + '\'' +
'}' + super.toString();
}
}

View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.test.alisa;
import com.mybatisflex.annotation.ViewObject;
/**
* 角色
*
* @author 王帅
* @since 2023-11-16
*/
@ViewObject(ref = SysRole.class)
public class RoleVO extends BaseEntity {
private Integer id;
private String roleKey;
private String roleName;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getRoleKey() {
return roleKey;
}
public void setRoleKey(String roleKey) {
this.roleKey = roleKey;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
@Override
public String toString() {
return "SysRole{" +
"id=" + id +
", roleKey='" + roleKey + '\'' +
", roleName='" + roleName + '\'' +
'}' + super.toString();
}
}

View File

@ -0,0 +1,103 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.test.alisa;
import com.mybatisflex.annotation.ColumnAlias;
import com.mybatisflex.annotation.ViewObject;
import java.util.Date;
import java.util.List;
/**
* 用户
*
* @author 王帅
* @since 2023-11-16
*/
@ViewObject(ref = SysUser.class)
public class UserVO extends BaseEntity {
private Integer id;
private String userName;
@ColumnAlias("user_age")
private Integer age;
private Date birthday;
private List<SysRole> roleList;
private List<SysDept> deptList;
public List<SysRole> getRoleList() {
return roleList;
}
public void setRoleList(List<SysRole> roleList) {
this.roleList = roleList;
}
public List<SysDept> getDeptList() {
return deptList;
}
public void setDeptList(List<SysDept> deptList) {
this.deptList = deptList;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
@Override
public String toString() {
return "SysUser{" +
"id=" + id +
", userName='" + userName + '\'' +
", age=" + age +
", birthday=" + birthday +
", roleList=" + roleList +
", deptList=" + deptList +
'}' + super.toString();
}
}

View File

@ -16,10 +16,13 @@
package com.mybatisflex.test.mapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.test.alisa.SysUser;
import com.mybatisflex.test.alisa.UserVO;
import org.apache.ibatis.mapping.ResultMap;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@ -63,7 +66,7 @@ class AlisaTest {
.select(SYS_USER.DEFAULT_COLUMNS)
.select(SYS_ROLE.DEFAULT_COLUMNS)
.from(SYS_USER.as("u"))
.leftJoin(SYS_ROLE).as("r").on(SYS_USER.ID.eq(1));
.leftJoin(SYS_ROLE.as("r")).on(SYS_USER.ID.eq(1));
printList(queryWrapper);
}
@ -75,8 +78,8 @@ class AlisaTest {
.select(SYS_ROLE.DEFAULT_COLUMNS)
.select(SYS_DEPT.DEFAULT_COLUMNS)
.from(SYS_USER.as("u"))
.leftJoin(SYS_ROLE).as("r").on(SYS_USER.ID.eq(1))
.leftJoin(SYS_DEPT).as("d").on(SYS_USER.ID.eq(1));
.leftJoin(SYS_ROLE.as("r")).on(SYS_USER.ID.eq(1))
.leftJoin(SYS_DEPT.as("d")).on(SYS_USER.ID.eq(1));
printList(queryWrapper);
}
@ -89,8 +92,8 @@ class AlisaTest {
.select(SYS_DEPT.DEFAULT_COLUMNS)
.select(SYS_USER.DEFAULT_COLUMNS)
.from(SYS_USER.as("u"))
.leftJoin(SYS_ROLE).as("r").on(SYS_USER.ID.eq(1))
.leftJoin(SYS_DEPT).as("d").on(SYS_USER.ID.eq(1));
.leftJoin(SYS_ROLE.as("r")).on(SYS_USER.ID.eq(1))
.leftJoin(SYS_DEPT.as("d")).on(SYS_USER.ID.eq(1));
printList(queryWrapper);
}
@ -126,7 +129,7 @@ class AlisaTest {
.select(SYS_USER.ID, SYS_USER.USER_NAME, SYS_USER.AGE, SYS_USER.BIRTHDAY)
.select(SYS_ROLE.CREATE_BY.as("sys_role$create_by"))
.from(SYS_USER.as("u"))
.leftJoin(SYS_ROLE).as("r").on(SYS_USER.ID.eq(1));
.leftJoin(SYS_ROLE.as("r")).on(SYS_USER.ID.eq(1));
Object[] objects = FlexGlobalConfig.getDefaultConfig()
.getConfiguration()
@ -145,4 +148,22 @@ class AlisaTest {
printList(queryWrapper);
}
@Test
void test07() throws JsonProcessingException {
QueryWrapper queryWrapper = QueryWrapper.create()
.select(SYS_USER.DEFAULT_COLUMNS)
.select(SYS_ROLE.DEFAULT_COLUMNS)
.select(SYS_DEPT.DEFAULT_COLUMNS)
.from(SYS_USER.as("u"))
.leftJoin(SYS_ROLE.as("r")).on(SYS_USER.ID.eq(1))
.leftJoin(SYS_DEPT.as("d")).on(SYS_USER.ID.eq(1));
ObjectWriter objectWriter = objectMapper.writerWithDefaultPrettyPrinter();
String userList1 = objectWriter.writeValueAsString(userMapper.selectListByQuery(queryWrapper));
String userList2 = objectWriter.writeValueAsString(userMapper.selectListByQueryAs(queryWrapper, UserVO.class));
Assertions.assertEquals(userList1, userList2);
}
}