diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/AccountVO2.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/AccountVO2.java new file mode 100644 index 00000000..0871f9ed --- /dev/null +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/AccountVO2.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * 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 + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * 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
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 + '\'' +
+ '}';
+ }
+}
\ No newline at end of file
diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/AccountMapperTest.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/AccountMapperTest.java
index 6c7db8b6..f669b0b8 100644
--- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/AccountMapperTest.java
+++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/AccountMapperTest.java
@@ -21,6 +21,7 @@ import com.mybatisflex.core.row.Db;
import com.mybatisflex.core.row.Row;
import com.mybatisflex.test.model.Account;
import com.mybatisflex.test.model.AccountVO;
+import com.mybatisflex.test.model.AccountVO2;
import com.mybatisflex.test.model.Gender;
import org.junit.jupiter.api.Assertions;
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.RoleTableDef.ROLE;
import static com.mybatisflex.test.model.table.UserRoleTableDef.USER_ROLE;
+import static com.mybatisflex.test.model.table.UserTableDef.USER;
/**
* @author 王帅
@@ -112,4 +114,19 @@ class AccountMapperTest {
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);
+ }
+
}
\ No newline at end of file