test: update test

This commit is contained in:
Michael Yang 2024-10-20 16:53:02 +08:00
parent f19f7adaa2
commit a854044a26
4 changed files with 41 additions and 12 deletions

View File

@ -96,8 +96,16 @@ public class QueryTable implements CloneSupport<QueryTable> {
if (this == table) { if (this == table) {
return true; return true;
} }
return Objects.equals(name, table.name)
&& Objects.equals(alias, table.alias); // return Objects.equals(name, table.name)
// && Objects.equals(alias, table.alias);
if (StringUtil.isNotBlank(alias)
&& StringUtil.isNotBlank(table.alias)) {
return Objects.equals(alias, table.alias);
}
return Objects.equals(name, table.name);
} }
Object[] getValueArray() { Object[] getValueArray() {

View File

@ -41,8 +41,8 @@ mybatis-flex:
ds1: ds1:
url: jdbc:mysql://127.0.0.1:3306/flex_test url: jdbc:mysql://127.0.0.1:3306/flex_test
username: root username: root
password: 12345678 password: 123456
ds2: ds2:
url: jdbc:mysql://127.0.0.1:3306/flex_test url: jdbc:mysql://127.0.0.1:3306/flex_test
username: root username: root
password: 12345678 password: 123456

View File

@ -18,6 +18,8 @@ package com.mybatisflex.test.mapper;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.test.entity.Outer; import com.mybatisflex.test.entity.Outer;
import com.mybatisflex.test.entity.table.InnerTableDef;
import com.mybatisflex.test.entity.table.OuterTableDef;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -49,16 +51,18 @@ class OuterMapperTest {
@Test @Test
void testSelect() { void testSelect() {
OuterTableDef outer = OUTER.as("o");
InnerTableDef inner = INNER.as("i");
QueryWrapper queryWrapper = QueryWrapper.create() QueryWrapper queryWrapper = QueryWrapper.create()
.select(OUTER.ID, .select(outer.ID,
OUTER.NAME, outer.NAME,
INNER.ID, inner.ID,
INNER.TYPE) inner.TYPE)
.from(OUTER.as("o")) .from(outer)
.leftJoin(INNER).as("i").on(INNER.ID.eq(2)) .leftJoin(inner).on(inner.ID.eq(2))
.limit(1); .limit(1);
Outer outer = outerMapper.selectOneByQuery(queryWrapper); Outer outer1 = outerMapper.selectOneByQuery(queryWrapper);
System.out.println(outer); System.out.println(outer1);
} }
} }

View File

@ -286,6 +286,23 @@ class UserMapperTest {
System.err.println(user); System.err.println(user);
} }
@Test
void testQueryWrapper() {
QueryWrapper queryWrapper = QueryWrapper.create()
.select(USER.USER_ID,
USER.USER_NAME,
ROLE.ROLE_NAME.as("roles"),
ROLE.ROLE_ID.as("role_ids"))
.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.eq(2));
String sql = queryWrapper.toSQL();
System.out.println(sql);
}
// @Test // @Test
// public void testFieldBindRelations() { // public void testFieldBindRelations() {
// List<UserVO5> userVO5List = userMapper.selectListWithRelationsByQueryAs(QueryWrapper.create(), UserVO5.class); // List<UserVO5> userVO5List = userMapper.selectListWithRelationsByQueryAs(QueryWrapper.create(), UserVO5.class);