diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/base/MPJBaseMapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/base/MPJBaseMapper.java index d98e85d..f9ca429 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/base/MPJBaseMapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/base/MPJBaseMapper.java @@ -46,6 +46,16 @@ public interface MPJBaseMapper extends BaseMapper { */ Long selectJoinCount(@Param(Constants.WRAPPER) MPJBaseJoin wrapper); + /** + * 连表查询返回一条记录 + * + * @param wrapper joinWrapper + * @return T + */ + default T selectJoinOne(@Param(Constants.WRAPPER) MPJBaseJoin wrapper) { + return selectJoinOne(null, wrapper); + } + /** * 连表查询返回一条记录 * @@ -65,6 +75,16 @@ public interface MPJBaseMapper extends BaseMapper { return selectJoinOne(Map.class, wrapper); } + /** + * 连表查询返回记录集合 + * + * @param wrapper joinWrapper + * @return List<T> + */ + default List selectJoinList(@Param(Constants.WRAPPER) MPJBaseJoin wrapper) { + return selectJoinList(null, wrapper); + } + /** * 连表查询返回记录集合 * @@ -84,6 +104,15 @@ public interface MPJBaseMapper extends BaseMapper { return (List>) ((Object) selectJoinList(Map.class, wrapper)); } + /** + * 连表查询返回记录集合并分页 + * + * @param wrapper joinWrapper + */ + default

> P selectJoinPage(P page, @Param(Constants.WRAPPER) MPJBaseJoin wrapper) { + return selectJoinPage(page, null, wrapper); + } + /** * 连表查询返回记录集合并分页 * diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java index 3534987..35ac7e6 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java @@ -66,14 +66,14 @@ public class MPJInterceptor implements Interceptor { if (Objects.nonNull(ew) && ew instanceof MPJBaseJoin) { if (CollectionUtils.isNotEmpty(map)) { Class rt = null; - if (map.containsKey(Constant.CLAZZ)) { + if (map.containsKey(Constant.CLAZZ) && map.get(Constant.CLAZZ) != null) { rt = (Class) map.get(Constant.CLAZZ); } else { 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) - && !MPJReflectionKit.isPrimitiveOrWrapper(type) && entity == type) { + && !MPJReflectionKit.isPrimitiveOrWrapper(type) && (entity == type)) { rt = type; } } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/MPJResultType.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/MPJResultType.java deleted file mode 100644 index 5883df7..0000000 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/MPJResultType.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.github.yulichang.method; - -import java.io.Serializable; - -/** - * result type 标识类 - * - * @author yulichang - */ -public class MPJResultType implements Serializable { -} diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinList.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinList.java index fcd4f17..bbd6dab 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinList.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinList.java @@ -32,7 +32,7 @@ public class SelectJoinList extends MPJAbstractMethod { String sql = String.format(sqlMethod.getSql(), sqlFirst(), sqlDistinct(), sqlSelectColumns(tableInfo, true), mpjTableName(tableInfo), sqlAlias(), sqlFrom(), sqlWhereEntityWrapper(true, tableInfo), mpjSqlOrderBy(tableInfo), sqlComment()); SqlSource sqlSource = languageDriver.createSqlSource(configuration, removeExtraWhitespaces(sql), modelClass); - return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, MPJResultType.class); + return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, tableInfo.getEntityType()); } @Override diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinOne.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinOne.java index 6b1042e..ac421db 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinOne.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinOne.java @@ -31,7 +31,7 @@ public class SelectJoinOne extends MPJAbstractMethod { String sql = String.format(sqlMethod.getSql(), sqlFirst(), sqlDistinct(), sqlSelectColumns(tableInfo, true), mpjTableName(tableInfo), sqlAlias(), sqlFrom(), sqlWhereEntityWrapper(true, tableInfo), sqlComment()); SqlSource sqlSource = languageDriver.createSqlSource(configuration, removeExtraWhitespaces(sql), modelClass); - return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, MPJResultType.class); + return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, tableInfo.getEntityType()); } @Override diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinPage.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinPage.java index f531bcb..1dec3e9 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinPage.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinPage.java @@ -32,7 +32,7 @@ public class SelectJoinPage extends MPJAbstractMethod { String sql = String.format(sqlMethod.getSql(), sqlFirst(), sqlDistinct(), sqlSelectColumns(tableInfo, true), mpjTableName(tableInfo), sqlAlias(), sqlFrom(), sqlWhereEntityWrapper(true, tableInfo), mpjSqlOrderBy(tableInfo), sqlComment()); SqlSource sqlSource = languageDriver.createSqlSource(configuration, removeExtraWhitespaces(sql), modelClass); - return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, MPJResultType.class); + return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, tableInfo.getEntityType()); } @Override diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/SelectJoinT_Test.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/SelectJoinT_Test.java new file mode 100644 index 0000000..7b92daf --- /dev/null +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/SelectJoinT_Test.java @@ -0,0 +1,48 @@ +package com.github.yulichang.test.join.unit; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.yulichang.test.join.entity.UserDO; +import com.github.yulichang.test.join.mapper.UserMapper; +import com.github.yulichang.test.util.Reset; +import com.github.yulichang.toolkit.JoinWrappers; +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 +@SuppressWarnings("NewClassNamingConvention") +public class SelectJoinT_Test { + + @Autowired + private UserMapper userMapper; + + @BeforeEach + void setUp() { + Reset.reset(); + } + + + @Test + void selectJoinT() { + UserDO userDO = userMapper.selectJoinOne(JoinWrappers.lambda().eq(UserDO::getId, 1)); + assert userDO != null; + System.out.println(userDO); + + List list = userMapper.selectJoinList(JoinWrappers.lambda()); + assert !list.isEmpty(); + list.forEach(i -> { + assert i != null; + System.out.println(i); + }); + + Page page = userMapper.selectJoinPage(new Page<>(1, 10), JoinWrappers.lambda()); + assert !page.getRecords().isEmpty(); + page.getRecords().forEach(i -> { + assert i != null; + System.out.println(i); + }); + } +}