mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
This commit is contained in:
parent
3d3762f470
commit
dbdea7b592
@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
import com.github.yulichang.method.MPJResultType;
|
||||
import com.github.yulichang.query.MPJQueryWrapper;
|
||||
import com.github.yulichang.toolkit.Constant;
|
||||
import com.github.yulichang.toolkit.MPJReflectionKit;
|
||||
@ -77,19 +76,14 @@ public class MPJInterceptor implements Interceptor {
|
||||
if (CollectionUtils.isNotEmpty(ms.getResultMaps())) {
|
||||
Class<?> entity = MPJTableMapperHelper.getEntity(getMapper(ms.getId(), ms.getResource()));
|
||||
Class<?> type = ms.getResultMaps().get(0).getType();
|
||||
if (Objects.nonNull(entity) && Objects.nonNull(type) && entity == type) {
|
||||
if (Objects.nonNull(entity) && Objects.nonNull(type)
|
||||
&& !MPJReflectionKit.isPrimitiveOrWrapper(type) && entity == type) {
|
||||
rt = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Objects.nonNull(rt)) {
|
||||
List<ResultMap> list = ms.getResultMaps();
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
ResultMap resultMap = list.get(0);
|
||||
if (resultMap.getType() == MPJResultType.class) {
|
||||
args[0] = getMappedStatement(ms, rt, ew);
|
||||
}
|
||||
}
|
||||
args[0] = getMappedStatement(ms, rt, ew);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,4 +104,34 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>flatten-maven-plugin</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<configuration>
|
||||
<!-- 是否更新pom文件,此处还有更高级的用法 -->
|
||||
<updatePomFile>true</updatePomFile>
|
||||
<flattenMode>resolveCiFriendliesOnly</flattenMode>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>flatten</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>flatten</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>flatten.clean</id>
|
||||
<phase>clean</phase>
|
||||
<goals>
|
||||
<goal>clean</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
@ -260,7 +260,6 @@ class LambdaWrapperTest {
|
||||
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void testMSCache() {
|
||||
ThreadLocalUtils.set("SELECT t.id,\n" +
|
||||
" t.pid,\n" +
|
||||
@ -738,7 +737,9 @@ class LambdaWrapperTest {
|
||||
.lt(UserDO::getId, 8));
|
||||
assert dos.size() == 4;
|
||||
|
||||
ThreadLocalUtils.set("SELECT id,pid,`name`,`json`,sex,head_img,create_time,address_id,address_id2,del,create_by,update_by FROM `user` t WHERE t.del=false AND (t.id > ? AND t.id < ?)",
|
||||
ThreadLocalUtils.set(
|
||||
"SELECT t.id, t.pid, t.`name`, t.`json`, t.sex, t.head_img, t.create_time, t.address_id, t.address_id2, t.del, t.create_by, t.update_by FROM `user` t WHERE t.del = false AND (t.id > ? AND t.id < ?)",
|
||||
"SELECT id, pid, `name`, `json`, sex, head_img, create_time, address_id, address_id2, del, create_by, update_by FROM `user` t WHERE t.del = false AND (t.id > ? AND t.id < ?)",
|
||||
"SELECT * FROM `user` t WHERE t.del=false AND (t.id > ? AND t.id < ?) ");
|
||||
List<UserDO> dos1 = userMapper.selectList(new MPJLambdaWrapper<UserDO>()
|
||||
.gt(UserDO::getId, 3)
|
||||
@ -993,6 +994,7 @@ class LambdaWrapperTest {
|
||||
void joinOrder() {
|
||||
if (VersionUtils.compare(MybatisPlusVersion.getVersion(), "3.4.3") >= 0) {
|
||||
ThreadLocalUtils.set("SELECT id,user_id,name FROM order_t t ORDER BY t.name DESC",
|
||||
"SELECT t.id, t.user_id, t.name FROM order_t t ORDER BY t.name DESC",
|
||||
"SELECT id,user_id,name FROM order_t t ORDER BY t.name desc");
|
||||
} else {
|
||||
ThreadLocalUtils.set("SELECT id,user_id,name FROM order_t t",
|
||||
|
@ -0,0 +1,59 @@
|
||||
package com.github.yulichang.test.join.m;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.github.yulichang.test.join.entity.AddressDO;
|
||||
import com.github.yulichang.test.join.entity.UserDO;
|
||||
import com.github.yulichang.test.join.entity.UserTenantDO;
|
||||
import com.github.yulichang.test.join.mapper.UserMapper;
|
||||
import com.github.yulichang.test.join.mapper.UserTenantMapper;
|
||||
import com.github.yulichang.test.util.Reset;
|
||||
import com.github.yulichang.toolkit.JoinWrappers;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class FieldAliasTest {
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Autowired
|
||||
private UserTenantMapper userTenantMapper;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Reset.reset();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void fieldAlias() {
|
||||
List<UserDO> list = userMapper.selectList(JoinWrappers.lambda(UserDO.class)
|
||||
.selectAll(UserDO.class)
|
||||
.leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId));
|
||||
|
||||
list.forEach(System.out::println);
|
||||
|
||||
assert list.get(0).getImg() != null;
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void fieldAlias1() {
|
||||
MPJLambdaWrapper<UserTenantDO> wrapper = JoinWrappers.lambda(UserTenantDO.class)
|
||||
.selectAll(UserTenantDO.class)
|
||||
.leftJoin(UserDO.class, UserDO::getId, UserTenantDO::getUuid);
|
||||
List<UserTenantDO> list = userTenantMapper.selectList(wrapper);
|
||||
|
||||
new LambdaQueryWrapper<UserDO>().getSqlSelect();
|
||||
list.forEach(System.out::println);
|
||||
System.out.println(wrapper.getSqlSelect());
|
||||
assert list.get(0).getIdea() != null;
|
||||
assert list.get(0).getUuid() != null;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user