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 b38c5e3..d98e85d 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 @@ -60,7 +60,10 @@ public interface MPJBaseMapper extends BaseMapper { * * @param wrapper joinWrapper */ - Map selectJoinMap(@Param(Constants.WRAPPER) MPJBaseJoin wrapper); + default Map selectJoinMap(@Param(Constants.WRAPPER) MPJBaseJoin wrapper) { + //noinspection unchecked + return selectJoinOne(Map.class, wrapper); + } /** * 连表查询返回记录集合 @@ -76,7 +79,10 @@ public interface MPJBaseMapper extends BaseMapper { * * @param wrapper joinWrapper */ - List> selectJoinMaps(@Param(Constants.WRAPPER) MPJBaseJoin wrapper); + default List> selectJoinMaps(@Param(Constants.WRAPPER) MPJBaseJoin wrapper) { + //noinspection unchecked + return (List>) ((Object) selectJoinList(Map.class, wrapper)); + } /** * 连表查询返回记录集合并分页 @@ -94,6 +100,9 @@ public interface MPJBaseMapper extends BaseMapper { * * @param wrapper joinWrapper */ -

>> P selectJoinMapsPage(P page, - @Param(Constants.WRAPPER) MPJBaseJoin wrapper); + default

>> P selectJoinMapsPage(P page, + @Param(Constants.WRAPPER) MPJBaseJoin wrapper) { + //noinspection unchecked,rawtypes + return (P) selectJoinPage((IPage) page, Map.class, wrapper); + } } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java index cb0dcc9..284c298 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java @@ -137,9 +137,6 @@ public class MPJSqlInjector extends DefaultSqlInjector { list.add(new SelectJoinOne(SqlMethod.SELECT_JOIN_ONE.getMethod())); list.add(new SelectJoinList(SqlMethod.SELECT_JOIN_LIST.getMethod())); list.add(new SelectJoinPage(SqlMethod.SELECT_JOIN_PAGE.getMethod())); - list.add(new SelectJoinMap(SqlMethod.SELECT_JOIN_MAP.getMethod())); - list.add(new SelectJoinMaps(SqlMethod.SELECT_JOIN_MAPS.getMethod())); - list.add(new SelectJoinMapsPage(SqlMethod.SELECT_JOIN_MAPS_PAGE.getMethod())); } else { list.add(new DeleteJoin()); list.add(new UpdateJoin()); @@ -148,9 +145,6 @@ public class MPJSqlInjector extends DefaultSqlInjector { list.add(new SelectJoinOne()); list.add(new SelectJoinList()); list.add(new SelectJoinPage()); - list.add(new SelectJoinMap()); - list.add(new SelectJoinMaps()); - list.add(new SelectJoinMapsPage()); } return list; } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinMap.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinMap.java deleted file mode 100644 index 4c73c8b..0000000 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinMap.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.github.yulichang.method; - -import com.baomidou.mybatisplus.core.metadata.TableInfo; -import com.baomidou.mybatisplus.core.toolkit.Constants; -import com.baomidou.mybatisplus.core.toolkit.StringPool; -import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils; -import com.github.yulichang.interfaces.MPJBaseJoin; -import org.apache.ibatis.mapping.MappedStatement; -import org.apache.ibatis.mapping.SqlSource; - -import java.util.Map; - -/** - * copy {@link com.baomidou.mybatisplus.core.injector.methods.SelectMaps} - * - * @author yulichang - */ -public class SelectJoinMap extends MPJAbstractMethod { - - @SuppressWarnings("deprecation") - public SelectJoinMap() { - super(); - } - - @SuppressWarnings("unused") - public SelectJoinMap(String name) { - super(name); - } - - @Override - public MappedStatement injectMappedStatement(Class mapperClass, Class modelClass, TableInfo tableInfo) { - SqlMethod sqlMethod = SqlMethod.SELECT_JOIN_MAP; - 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, Map.class); - } - - @Override - protected String sqlComment() { - return super.sqlComment() + StringPool.NEWLINE + SqlScriptUtils.convertIf("${ew.unionSql}", String.format("%s != null and (%s instanceof %s)", - Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), true); - } -} diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinMaps.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinMaps.java deleted file mode 100644 index 446cf80..0000000 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinMaps.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.yulichang.method; - -import com.baomidou.mybatisplus.core.metadata.TableInfo; -import com.baomidou.mybatisplus.core.toolkit.Constants; -import com.baomidou.mybatisplus.core.toolkit.StringPool; -import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils; -import com.github.yulichang.interfaces.MPJBaseJoin; -import org.apache.ibatis.mapping.MappedStatement; -import org.apache.ibatis.mapping.SqlSource; - -import java.util.Map; - -/** - * copy {@link com.baomidou.mybatisplus.core.injector.methods.SelectMaps} - * - * @author yulichang - */ -public class SelectJoinMaps extends MPJAbstractMethod { - - @SuppressWarnings("deprecation") - public SelectJoinMaps() { - super(); - } - - @SuppressWarnings("unused") - public SelectJoinMaps(String name) { - super(name); - } - - @Override - @SuppressWarnings("DuplicatedCode") - public MappedStatement injectMappedStatement(Class mapperClass, Class modelClass, TableInfo tableInfo) { - SqlMethod sqlMethod = SqlMethod.SELECT_JOIN_MAPS; - 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, Map.class); - } - - @Override - protected String sqlComment() { - return super.sqlComment() + StringPool.NEWLINE + SqlScriptUtils.convertIf("${ew.unionSql}", String.format("%s != null and (%s instanceof %s)", - Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), true); - } -} diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinMapsPage.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinMapsPage.java deleted file mode 100644 index 60a1ed4..0000000 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinMapsPage.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.yulichang.method; - -import com.baomidou.mybatisplus.core.metadata.TableInfo; -import com.baomidou.mybatisplus.core.toolkit.Constants; -import com.baomidou.mybatisplus.core.toolkit.StringPool; -import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils; -import com.github.yulichang.interfaces.MPJBaseJoin; -import org.apache.ibatis.mapping.MappedStatement; -import org.apache.ibatis.mapping.SqlSource; - -import java.util.Map; - -/** - * copy {@link com.baomidou.mybatisplus.core.injector.methods.SelectMaps} - * - * @author yulichang - */ -public class SelectJoinMapsPage extends MPJAbstractMethod { - - @SuppressWarnings("deprecation") - public SelectJoinMapsPage() { - super(); - } - - @SuppressWarnings("unused") - public SelectJoinMapsPage(String name) { - super(name); - } - - @Override - @SuppressWarnings("DuplicatedCode") - public MappedStatement injectMappedStatement(Class mapperClass, Class modelClass, TableInfo tableInfo) { - SqlMethod sqlMethod = SqlMethod.SELECT_JOIN_MAPS_PAGE; - 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, Map.class); - } - - @Override - protected String sqlComment() { - return super.sqlComment() + StringPool.NEWLINE + SqlScriptUtils.convertIf("${ew.unionSql}", String.format("%s != null and (%s instanceof %s)", - Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), true); - } -} diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SqlMethod.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SqlMethod.java index 26dc29b..7afe4c3 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SqlMethod.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SqlMethod.java @@ -1,5 +1,7 @@ package com.github.yulichang.method; +import lombok.Getter; + import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -9,6 +11,7 @@ import java.util.stream.Collectors; * @see com.baomidou.mybatisplus.core.enums.SqlMethod * @since 2021/1/15 */ +@Getter public enum SqlMethod { /** * 连表查询 @@ -22,18 +25,9 @@ public enum SqlMethod { SELECT_JOIN_LIST("selectJoinList", "返回List集合", ""), - SELECT_JOIN_MAP("selectJoinMap", "返回一个Map", - ""), - - SELECT_JOIN_MAPS("selectJoinMaps", "返回Map集合", - ""), - SELECT_JOIN_PAGE("selectJoinPage", "连表查询并分页", ""), - SELECT_JOIN_MAPS_PAGE("selectJoinMapsPage", "返回Map集合并分页", - ""), - /** * 连表删除 */ @@ -64,15 +58,6 @@ public enum SqlMethod { this.sql = sql; } - public String getMethod() { - return method; - } - - - public String getSql() { - return sql; - } - public static final List collect = Arrays.stream(SqlMethod.values()).map(SqlMethod::getMethod).collect(Collectors.toList()); }