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
e346d0e219
commit
cc59ef7b45
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* 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.model;
|
||||||
|
|
||||||
|
import com.mybatisflex.annotation.As;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 王帅
|
||||||
|
* @since 2023-06-30
|
||||||
|
*/
|
||||||
|
public class AccountVO2 extends IdEntity<Long> {
|
||||||
|
|
||||||
|
private Integer age;
|
||||||
|
@As("account_name")
|
||||||
|
private String userName;
|
||||||
|
private UserVO4 user;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@As("account_id")
|
||||||
|
public Long getId() {
|
||||||
|
return super.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getAge() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAge(Integer age) {
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserName() {
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserName(String userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserVO4 getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(UserVO4 user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "AccountVO2{" +
|
||||||
|
"id=" + id +
|
||||||
|
", age=" + age +
|
||||||
|
", userName='" + userName + '\'' +
|
||||||
|
", user='" + user + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* 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.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户 VO 对象。
|
||||||
|
*
|
||||||
|
* @author 王帅
|
||||||
|
* @since 2023-06-30
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class UserVO4 {
|
||||||
|
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
public String getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(String userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserName() {
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserName(String userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "UserVO{" +
|
||||||
|
"userId='" + userId + '\'' +
|
||||||
|
", userName='" + userName + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -21,6 +21,7 @@ import com.mybatisflex.core.row.Db;
|
|||||||
import com.mybatisflex.core.row.Row;
|
import com.mybatisflex.core.row.Row;
|
||||||
import com.mybatisflex.test.model.Account;
|
import com.mybatisflex.test.model.Account;
|
||||||
import com.mybatisflex.test.model.AccountVO;
|
import com.mybatisflex.test.model.AccountVO;
|
||||||
|
import com.mybatisflex.test.model.AccountVO2;
|
||||||
import com.mybatisflex.test.model.Gender;
|
import com.mybatisflex.test.model.Gender;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -33,6 +34,7 @@ import java.util.List;
|
|||||||
import static com.mybatisflex.test.model.table.AccountTableDef.ACCOUNT;
|
import static com.mybatisflex.test.model.table.AccountTableDef.ACCOUNT;
|
||||||
import static com.mybatisflex.test.model.table.RoleTableDef.ROLE;
|
import static com.mybatisflex.test.model.table.RoleTableDef.ROLE;
|
||||||
import static com.mybatisflex.test.model.table.UserRoleTableDef.USER_ROLE;
|
import static com.mybatisflex.test.model.table.UserRoleTableDef.USER_ROLE;
|
||||||
|
import static com.mybatisflex.test.model.table.UserTableDef.USER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 王帅
|
* @author 王帅
|
||||||
@ -112,4 +114,19 @@ class AccountMapperTest {
|
|||||||
accountMapper.deleteByQuery(QueryWrapper.create()));
|
accountMapper.deleteByQuery(QueryWrapper.create()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testAs() {
|
||||||
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
|
.select(ACCOUNT.ID.as("account_id"),
|
||||||
|
ACCOUNT.AGE,
|
||||||
|
ACCOUNT.USER_NAME.as("account_name"),
|
||||||
|
USER.USER_ID,
|
||||||
|
USER.USER_NAME)
|
||||||
|
.from(ACCOUNT.as("a"), USER.as("u"))
|
||||||
|
.where(ACCOUNT.ID.eq(1))
|
||||||
|
.limit(1);
|
||||||
|
AccountVO2 account = accountMapper.selectOneByQueryAs(queryWrapper, AccountVO2.class);
|
||||||
|
System.out.println(account);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user