简化代码

This commit is contained in:
yulichang 2024-09-11 17:45:04 +08:00
parent 1b3f294645
commit 6be7f0bc21
36 changed files with 134 additions and 128 deletions

View File

@ -1,11 +0,0 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "gradle" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"

View File

@ -9,8 +9,8 @@ import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.adapter.AdapterHelper; import com.github.yulichang.adapter.AdapterHelper;
import com.github.yulichang.apt.BaseColumn; import com.github.yulichang.extension.apt.matedata.BaseColumn;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import com.github.yulichang.config.ConfigProperties; import com.github.yulichang.config.ConfigProperties;
import com.github.yulichang.config.enums.LogicDelTypeEnum; import com.github.yulichang.config.enums.LogicDelTypeEnum;
import com.github.yulichang.extension.apt.interfaces.QueryJoin; import com.github.yulichang.extension.apt.interfaces.QueryJoin;

View File

@ -5,8 +5,8 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments; import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.core.toolkit.*; import com.baomidou.mybatisplus.core.toolkit.*;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.apt.BaseColumn; import com.github.yulichang.extension.apt.matedata.BaseColumn;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import com.github.yulichang.config.ConfigProperties; import com.github.yulichang.config.ConfigProperties;
import com.github.yulichang.extension.apt.interfaces.Query; import com.github.yulichang.extension.apt.interfaces.Query;
import com.github.yulichang.extension.apt.interfaces.QueryLabel; import com.github.yulichang.extension.apt.interfaces.QueryLabel;

View File

@ -12,7 +12,7 @@ import com.baomidou.mybatisplus.core.toolkit.*;
import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils; import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
import com.baomidou.mybatisplus.core.toolkit.sql.StringEscape; import com.baomidou.mybatisplus.core.toolkit.sql.StringEscape;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import com.github.yulichang.config.ConfigProperties; import com.github.yulichang.config.ConfigProperties;
import com.github.yulichang.extension.apt.interfaces.CompareIfExists; import com.github.yulichang.extension.apt.interfaces.CompareIfExists;
import com.github.yulichang.extension.apt.interfaces.Func; import com.github.yulichang.extension.apt.interfaces.Func;

View File

@ -1,6 +1,6 @@
package com.github.yulichang.extension.apt.interfaces; package com.github.yulichang.extension.apt.interfaces;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import java.io.Serializable; import java.io.Serializable;

View File

@ -1,6 +1,6 @@
package com.github.yulichang.extension.apt.interfaces; package com.github.yulichang.extension.apt.interfaces;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum; import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
import java.util.function.BiPredicate; import java.util.function.BiPredicate;

View File

@ -1,6 +1,6 @@
package com.github.yulichang.extension.apt.interfaces; package com.github.yulichang.extension.apt.interfaces;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;

View File

@ -1,6 +1,6 @@
package com.github.yulichang.extension.apt.interfaces; package com.github.yulichang.extension.apt.interfaces;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import java.io.Serializable; import java.io.Serializable;

View File

@ -3,8 +3,8 @@ package com.github.yulichang.extension.apt.interfaces;
import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.apt.BaseColumn; import com.github.yulichang.extension.apt.matedata.BaseColumn;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import com.github.yulichang.toolkit.Constant; import com.github.yulichang.toolkit.Constant;
import com.github.yulichang.toolkit.LambdaUtils; import com.github.yulichang.toolkit.LambdaUtils;
import com.github.yulichang.toolkit.MPJReflectionKit; import com.github.yulichang.toolkit.MPJReflectionKit;

View File

@ -1,7 +1,7 @@
package com.github.yulichang.extension.apt.interfaces; package com.github.yulichang.extension.apt.interfaces;
import com.github.yulichang.apt.BaseColumn; import com.github.yulichang.extension.apt.matedata.BaseColumn;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import com.github.yulichang.interfaces.MPJBaseJoin; import com.github.yulichang.interfaces.MPJBaseJoin;
import com.github.yulichang.query.interfaces.StringJoin; import com.github.yulichang.query.interfaces.StringJoin;
import com.github.yulichang.toolkit.Constant; import com.github.yulichang.toolkit.Constant;

View File

@ -2,7 +2,7 @@ package com.github.yulichang.extension.apt.interfaces;
import com.baomidou.mybatisplus.core.toolkit.Assert; import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.apt.BaseColumn; import com.github.yulichang.extension.apt.matedata.BaseColumn;
import com.github.yulichang.toolkit.LambdaUtils; import com.github.yulichang.toolkit.LambdaUtils;
import com.github.yulichang.toolkit.MPJReflectionKit; import com.github.yulichang.toolkit.MPJReflectionKit;
import com.github.yulichang.toolkit.support.FieldCache; import com.github.yulichang.toolkit.support.FieldCache;

View File

@ -1,4 +1,4 @@
package com.github.yulichang.apt; package com.github.yulichang.extension.apt.matedata;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package com.github.yulichang.apt; package com.github.yulichang.extension.apt.matedata;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package com.github.yulichang.apt; package com.github.yulichang.extension.apt.matedata;
import lombok.Getter; import lombok.Getter;

View File

@ -4,8 +4,8 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.Assert; import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.apt.BaseColumn; import com.github.yulichang.extension.apt.matedata.BaseColumn;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import com.github.yulichang.toolkit.LambdaUtils; import com.github.yulichang.toolkit.LambdaUtils;
import com.github.yulichang.toolkit.MPJReflectionKit; import com.github.yulichang.toolkit.MPJReflectionKit;
import com.github.yulichang.toolkit.TableHelper; import com.github.yulichang.toolkit.TableHelper;

View File

@ -4,8 +4,8 @@ import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils; import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.apt.BaseColumn; import com.github.yulichang.extension.apt.matedata.BaseColumn;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import com.github.yulichang.toolkit.LambdaUtils; import com.github.yulichang.toolkit.LambdaUtils;
import com.github.yulichang.toolkit.MPJReflectionKit; import com.github.yulichang.toolkit.MPJReflectionKit;
import com.github.yulichang.toolkit.support.ColumnCache; import com.github.yulichang.toolkit.support.ColumnCache;

View File

@ -2,8 +2,8 @@ package com.github.yulichang.extension.apt.resultmap;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.apt.BaseColumn; import com.github.yulichang.extension.apt.matedata.BaseColumn;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import com.github.yulichang.toolkit.LambdaUtils; import com.github.yulichang.toolkit.LambdaUtils;
import com.github.yulichang.toolkit.support.ColumnCache; import com.github.yulichang.toolkit.support.ColumnCache;
import com.github.yulichang.wrapper.resultmap.IResult; import com.github.yulichang.wrapper.resultmap.IResult;

View File

@ -1,6 +1,6 @@
package com.github.yulichang.extension.apt.toolkit; package com.github.yulichang.extension.apt.toolkit;
import com.github.yulichang.apt.BaseColumn; import com.github.yulichang.extension.apt.matedata.BaseColumn;
import com.github.yulichang.extension.apt.AptQueryWrapper; import com.github.yulichang.extension.apt.AptQueryWrapper;
/** /**

View File

@ -3,12 +3,14 @@ package com.github.yulichang.interceptor;
import com.baomidou.mybatisplus.core.MybatisPlusVersion; import com.baomidou.mybatisplus.core.MybatisPlusVersion;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.*; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.github.yulichang.adapter.AdapterHelper; import com.github.yulichang.adapter.AdapterHelper;
import com.github.yulichang.adapter.base.tookit.VersionUtils; import com.github.yulichang.adapter.base.tookit.VersionUtils;
import com.github.yulichang.config.ConfigProperties; import com.github.yulichang.config.ConfigProperties;
import com.github.yulichang.interfaces.MPJBaseJoin; import com.github.yulichang.interfaces.MPJBaseJoin;
import com.github.yulichang.toolkit.ReflectionKit;
import com.github.yulichang.toolkit.*; import com.github.yulichang.toolkit.*;
import com.github.yulichang.toolkit.support.FieldCache; import com.github.yulichang.toolkit.support.FieldCache;
import com.github.yulichang.wrapper.interfaces.SelectWrapper; import com.github.yulichang.wrapper.interfaces.SelectWrapper;
@ -100,16 +102,10 @@ public class MPJInterceptor implements Interceptor {
wrapper.selectAll(); wrapper.selectAll();
} }
if (wrapper.isResultMapCollection()) { if (wrapper.isResultMapCollection()) {
if (map.values().stream().anyMatch(a -> a instanceof IPage)) { if (map.values().stream().anyMatch(a -> a instanceof IPage) && !wrapper.isPageByMain()) {
if (wrapper.isPageByMain()) { AdapterHelper.getAdapter().checkCollectionPage();
AdapterHelper.getAdapter().checkCollectionPage(); // 一对多分页问题警告
IPage<?> page = ParameterUtils.findPage(map).orElse(null); log.warn("select one to many and page query will result in errors in the total count statistics, please use xml.");
wrapper.getPageInfo().setInnerPage(page);
map.entrySet().removeIf(entry -> entry.getValue() instanceof IPage);
} else {
// 一对多分页问题警告
log.warn("select one to many and page query will result in errors in the total count statistics, please use xml.");
}
} }
} }
} }

View File

@ -2,10 +2,7 @@ package com.github.yulichang.interceptor.pagination;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.*;
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.extension.parser.JsqlParserGlobal; import com.baomidou.mybatisplus.extension.parser.JsqlParserGlobal;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.dialects.IDialect; import com.baomidou.mybatisplus.extension.plugins.pagination.dialects.IDialect;
@ -35,12 +32,14 @@ import java.util.stream.Collectors;
* @author yulichang * @author yulichang
* @since 1.5.0 * @since 1.5.0
*/ */
public class PageInnerInterceptor extends PaginationInnerInterceptor { public class PageInnerInterceptorWrapper extends PaginationInnerInterceptor {
private static final Log log = LogFactory.getLog(PageInnerInterceptorWrapper.class);
private static final Log log = LogFactory.getLog(PageInnerInterceptor.class); private final PaginationInnerInterceptor paginationInnerInterceptor;
public PageInnerInterceptor(PaginationInnerInterceptor pagination) { public PageInnerInterceptorWrapper(PaginationInnerInterceptor pagination) {
this.paginationInnerInterceptor = pagination;
super.setOptimizeJoin(true); super.setOptimizeJoin(true);
super.setDbType(pagination.getDbType()); super.setDbType(pagination.getDbType());
super.setDialect(pagination.getDialect()); super.setDialect(pagination.getDialect());
@ -53,13 +52,13 @@ public class PageInnerInterceptor extends PaginationInnerInterceptor {
*/ */
@Override @Override
public boolean willDoQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException { public boolean willDoQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
//没有wrapper 或者 不是对多查询 不做处理 if (unusedPage(parameter)) {
SelectWrapper<?, ?> wrapper = findMPJWrapper(parameter).orElse(null); return paginationInnerInterceptor.willDoQuery(executor, ms, parameter, rowBounds, resultHandler, boundSql);
if (wrapper == null || !wrapper.isPageByMain()) {
return true;
} }
//没有wrapper 或者 不是对多查询 不做处理
SelectWrapper<?, ?> wrapper = findMPJWrapper(parameter).orElseThrow(RuntimeException::new);
// copy super // copy super
IPage<?> page = wrapper.getPageInfo().getInnerPage(); IPage<?> page = ParameterUtils.findPage(parameter).orElse(null);
if (page == null || page.getSize() < 0 || !page.searchCount() || resultHandler != Executor.NO_RESULT_HANDLER) { if (page == null || page.getSize() < 0 || !page.searchCount() || resultHandler != Executor.NO_RESULT_HANDLER) {
return true; return true;
} }
@ -95,17 +94,16 @@ public class PageInnerInterceptor extends PaginationInnerInterceptor {
* 添加分页方言 * 添加分页方言
*/ */
@Override @Override
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) { public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
SelectWrapper<?, ?> wrapper = findMPJWrapper(parameter).orElse(null); if (unusedPage(parameter)) {
if (wrapper == null || !wrapper.isPageByMain()) { paginationInnerInterceptor.beforeQuery(executor, ms, parameter, rowBounds, resultHandler, boundSql);
return; return;
} }
// copy super // copy super
IPage<?> page = wrapper.getPageInfo().getInnerPage(); IPage<?> page = ParameterUtils.findPage(parameter).orElse(null);
if (null == page) { if (null == page) {
return; return;
} }
// 处理 orderBy 拼接 // 处理 orderBy 拼接
boolean addOrdered = false; boolean addOrdered = false;
String buildSql = boundSql.getSql(); String buildSql = boundSql.getSql();
@ -137,12 +135,11 @@ public class PageInnerInterceptor extends PaginationInnerInterceptor {
mpBoundSql.parameterMappings(dialect.getFullMappings()); mpBoundSql.parameterMappings(dialect.getFullMappings());
} }
@Override private boolean unusedPage(Object parameter) {
public void setProperties(Properties properties) { return !findMPJWrapper(parameter).map(SelectWrapper::isPageByMain).orElse(false);
super.setProperties(properties);
} }
public String autoCountSql(String sql, List<ParameterMapping> mappings, MappedStatement ms, Object parameter, SelectWrapper<?, ?> wrapper) { private String autoCountSql(String sql, List<ParameterMapping> mappings, MappedStatement ms, Object parameter, SelectWrapper<?, ?> wrapper) {
try { try {
Select select = (Select) JsqlParserGlobal.parse(sql); Select select = (Select) JsqlParserGlobal.parse(sql);
if (select instanceof SetOperationList) { if (select instanceof SetOperationList) {
@ -228,12 +225,12 @@ public class PageInnerInterceptor extends PaginationInnerInterceptor {
throw ExceptionUtils.mpe("not support this sql, please use xml. error sql: " + sql); throw ExceptionUtils.mpe("not support this sql, please use xml. error sql: " + sql);
} }
protected DialectWrapper findMPJDialect(Executor executor) { private DialectWrapper findMPJDialect(Executor executor) {
IDialect dialect = super.findIDialect(executor); IDialect dialect = super.findIDialect(executor);
return new DialectWrapper(dialect); return new DialectWrapper(dialect);
} }
public static Optional<SelectWrapper<?, ?>> findMPJWrapper(Object parameterObject) { private static Optional<SelectWrapper<?, ?>> findMPJWrapper(Object parameterObject) {
if (parameterObject != null) { if (parameterObject != null) {
if (parameterObject instanceof Map) { if (parameterObject instanceof Map) {
Map<?, ?> parameterMap = (Map<?, ?>) parameterObject; Map<?, ?> parameterMap = (Map<?, ?>) parameterObject;

View File

@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.github.yulichang.adapter.AdapterHelper; import com.github.yulichang.adapter.AdapterHelper;
import com.github.yulichang.interceptor.MPJInterceptor; import com.github.yulichang.interceptor.MPJInterceptor;
import com.github.yulichang.interceptor.pagination.PageInnerInterceptor; import com.github.yulichang.interceptor.pagination.PageInnerInterceptorWrapper;
import org.apache.ibatis.logging.Log; import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory; import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.plugin.Interceptor; import org.apache.ibatis.plugin.Interceptor;
@ -40,45 +40,12 @@ public class InterceptorList<E extends Interceptor> extends ArrayList<E> {
super.removeIf(predicate); super.removeIf(predicate);
super.add(mpjInterceptor); super.add(mpjInterceptor);
} }
try { this.forEach(this::wrapperInnerPage);
AdapterHelper.getAdapter().checkCollectionPage();
} catch (Exception e) {
return;
}
if (this.stream().anyMatch(i -> i instanceof MybatisPlusInterceptor)) {
MybatisPlusInterceptor mybatisPlusInterceptor = super.stream().filter(i -> i instanceof MybatisPlusInterceptor)
.map(i -> (MybatisPlusInterceptor) i).findFirst().orElse(null);
if (mybatisPlusInterceptor != null) {
try {
Field field = MybatisPlusInterceptor.class.getDeclaredField("interceptors");
field.setAccessible(true);
@SuppressWarnings("unchecked")
List<InnerInterceptor> interceptors = (List<InnerInterceptor>) field.get(mybatisPlusInterceptor);
Integer index = null;
PaginationInnerInterceptor paginationInnerInterceptor = null;
if (interceptors.stream().noneMatch(i -> i instanceof PageInnerInterceptor)) {
for (int i = 0; i < interceptors.size(); i++) {
InnerInterceptor innerInterceptor = interceptors.get(i);
if (innerInterceptor instanceof PaginationInnerInterceptor) {
paginationInnerInterceptor = (PaginationInnerInterceptor) innerInterceptor;
index = i;
break;
}
}
}
if (index != null) {
interceptors.add(index + 1, new PageInnerInterceptor(paginationInnerInterceptor));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
} }
@Override @Override
public boolean add(E e) { public boolean add(E e) {
this.wrapperInnerPage(e);
if (this.isEmpty()) { if (this.isEmpty()) {
return super.add(e); return super.add(e);
} }
@ -91,4 +58,42 @@ public class InterceptorList<E extends Interceptor> extends ArrayList<E> {
} }
return add; return add;
} }
@Override
public boolean addAll(Collection<? extends E> c) {
c.forEach(this::wrapperInnerPage);
return super.addAll(c);
}
@Override
public boolean addAll(int index, Collection<? extends E> c) {
c.forEach(this::wrapperInnerPage);
return super.addAll(index, c);
}
private void wrapperInnerPage(Interceptor interceptor) {
try {
AdapterHelper.getAdapter().checkCollectionPage();
} catch (Exception e) {
return;
}
if (interceptor instanceof MybatisPlusInterceptor) {
MybatisPlusInterceptor mybatisPlusInterceptor = (MybatisPlusInterceptor) interceptor;
try {
Field field = MybatisPlusInterceptor.class.getDeclaredField("interceptors");
field.setAccessible(true);
@SuppressWarnings("unchecked")
List<InnerInterceptor> interceptors = (List<InnerInterceptor>) field.get(mybatisPlusInterceptor);
interceptors.replaceAll(i -> {
if (i instanceof PaginationInnerInterceptor && !(i instanceof PageInnerInterceptorWrapper)) {
return new PageInnerInterceptorWrapper((PaginationInnerInterceptor) i);
}
return i;
});
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
} }

View File

@ -1,7 +1,7 @@
package com.github.yulichang.toolkit; package com.github.yulichang.toolkit;
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils; import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
import com.github.yulichang.apt.BaseColumn; import com.github.yulichang.extension.apt.matedata.BaseColumn;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;

View File

@ -1,6 +1,6 @@
package com.github.yulichang.wrapper.resultmap; package com.github.yulichang.wrapper.resultmap;
import com.github.yulichang.apt.BaseColumn; import com.github.yulichang.extension.apt.matedata.BaseColumn;
import com.github.yulichang.wrapper.segments.SelectCache; import com.github.yulichang.wrapper.segments.SelectCache;
import org.apache.ibatis.type.JdbcType; import org.apache.ibatis.type.JdbcType;

View File

@ -1,6 +1,6 @@
package com.github.yulichang.wrapper.segments; package com.github.yulichang.wrapper.segments;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import java.io.Serializable; import java.io.Serializable;

View File

@ -1,6 +1,5 @@
package com.github.yulichang.wrapper.segments; package com.github.yulichang.wrapper.segments;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -18,7 +17,5 @@ import java.io.Serializable;
@AllArgsConstructor @AllArgsConstructor
public class PageInfo implements Serializable { public class PageInfo implements Serializable {
private IPage<?> innerPage;
private String countSelectSql; private String countSelectSql;
} }

View File

@ -1,7 +1,7 @@
package com.github.yulichang.wrapper.segments; package com.github.yulichang.wrapper.segments;
import com.github.yulichang.apt.BaseColumn; import com.github.yulichang.extension.apt.matedata.BaseColumn;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import com.github.yulichang.wrapper.enums.BaseFuncEnum; import com.github.yulichang.wrapper.enums.BaseFuncEnum;
import org.apache.ibatis.type.JdbcType; import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler; import org.apache.ibatis.type.TypeHandler;

View File

@ -1,7 +1,7 @@
package com.github.yulichang.wrapper.segments; package com.github.yulichang.wrapper.segments;
import com.github.yulichang.apt.BaseColumn; import com.github.yulichang.extension.apt.matedata.BaseColumn;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import com.github.yulichang.wrapper.enums.BaseFuncEnum; import com.github.yulichang.wrapper.enums.BaseFuncEnum;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;

View File

@ -1,7 +1,7 @@
package com.github.yulichang.wrapper.segments; package com.github.yulichang.wrapper.segments;
import com.github.yulichang.apt.BaseColumn; import com.github.yulichang.extension.apt.matedata.BaseColumn;
import com.github.yulichang.wrapper.enums.BaseFuncEnum; import com.github.yulichang.wrapper.enums.BaseFuncEnum;
import lombok.Getter; import lombok.Getter;
import org.apache.ibatis.type.JdbcType; import org.apache.ibatis.type.JdbcType;

View File

@ -3,7 +3,12 @@ package com.github.yulichang.test.join.mapper;
import com.github.yulichang.test.join.entity.AreaDO; import com.github.yulichang.test.join.entity.AreaDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.awt.geom.Area;
import java.util.List;
@Mapper @Mapper
@SuppressWarnings("unused") @SuppressWarnings("unused")
public interface AreaMapper extends MyBaseMapper<AreaDO> { public interface AreaMapper extends MyBaseMapper<AreaDO> {
List<Area> all();
} }

View File

@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.github.yulichang.test.join.mapper.UserMapper"> <mapper namespace="com.github.yulichang.test.join.mapper.AreaMapper">
<select id="all" resultType="com.github.yulichang.test.join.entity.AreaDO">
select * from area
</select>
</mapper> </mapper>

View File

@ -1,7 +1,7 @@
package com.github.yulichang.test.join.apt.unit; package com.github.yulichang.test.join.apt.unit;
import com.github.yulichang.apt.BaseColumn; import com.github.yulichang.extension.apt.matedata.BaseColumn;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import com.github.yulichang.test.join.entity.UserDO; import com.github.yulichang.test.join.entity.UserDO;
import com.github.yulichang.test.join.entity.apt.UserDOCol; import com.github.yulichang.test.join.entity.apt.UserDOCol;
import com.github.yulichang.test.join.mapper.UserMapper; import com.github.yulichang.test.join.mapper.UserMapper;

View File

@ -1,6 +1,6 @@
package com.github.yulichang.test.join.apt.unit; package com.github.yulichang.test.join.apt.unit;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import com.github.yulichang.extension.apt.AptQueryWrapper; import com.github.yulichang.extension.apt.AptQueryWrapper;
import com.github.yulichang.extension.apt.toolkit.AptWrappers; import com.github.yulichang.extension.apt.toolkit.AptWrappers;
import com.github.yulichang.test.join.dto.UserDTO; import com.github.yulichang.test.join.dto.UserDTO;

View File

@ -4,17 +4,30 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.test.join.dto.UserDTO; import com.github.yulichang.test.join.dto.UserDTO;
import com.github.yulichang.test.join.entity.AddressDO; import com.github.yulichang.test.join.entity.AddressDO;
import com.github.yulichang.test.join.entity.UserDO; import com.github.yulichang.test.join.entity.UserDO;
import com.github.yulichang.test.join.mapper.AreaMapper;
import com.github.yulichang.test.util.ThreadLocalUtils; import com.github.yulichang.test.util.ThreadLocalUtils;
import com.github.yulichang.toolkit.JoinWrappers; import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import java.awt.geom.Area;
import java.util.List;
@SpringBootTest @SpringBootTest
public class PageByMainTest { public class PageByMainTest {
@Autowired
private AreaMapper areaMapper;
@Test @Test
void pageByMain() { void pageByMain() {
List<Area> all = areaMapper.all();
System.out.println(all);
assert !all.isEmpty();
ThreadLocalUtils.set("SELECT t.id, t.pid, t.`name`, t.`json`, t.sex, t.head_img, t.create_time, t.address_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, t1.id AS joina_id, t1.user_id, t1.area_id, t1.tel, " + "t.address_id2, t.del, t.create_by, t.update_by, t1.id AS joina_id, t1.user_id, t1.area_id, t1.tel, " +
"t1.address, t1.del AS joina_del FROM (SELECT * FROM `user` t WHERE t.del = false AND (t.id <= ?) LIMIT ?) t " + "t1.address, t1.del AS joina_del FROM (SELECT * FROM `user` t WHERE t.del = false AND (t.id <= ?) LIMIT ?) t " +

View File

@ -18,7 +18,7 @@
<dependency> <dependency>
<groupId>com.github.yulichang</groupId> <groupId>com.github.yulichang</groupId>
<artifactId>mybatis-plus-join-core</artifactId> <artifactId>mybatis-plus-join-core</artifactId>
<version>1.4.13</version> <version>${revision}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.baomidou</groupId> <groupId>com.baomidou</groupId>
@ -26,9 +26,10 @@
<version>${mpj.mybatis.plus.version}</version> <version>${mpj.mybatis.plus.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mybatis</groupId> <groupId>com.baomidou</groupId>
<artifactId>mybatis</artifactId> <artifactId>mybatis-plus-extension</artifactId>
<version>3.5.16</version> <version>3.5.7</version>
<scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -2,8 +2,8 @@ package com.github.yulichang.processor;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.github.yulichang.annotation.Table; import com.github.yulichang.annotation.Table;
import com.github.yulichang.apt.BaseColumn; import com.github.yulichang.extension.apt.matedata.BaseColumn;
import com.github.yulichang.apt.Column; import com.github.yulichang.extension.apt.matedata.Column;
import com.github.yulichang.processor.matedata.Conf; import com.github.yulichang.processor.matedata.Conf;
import com.github.yulichang.processor.matedata.FieldInfo; import com.github.yulichang.processor.matedata.FieldInfo;
import com.github.yulichang.processor.matedata.TableInfo; import com.github.yulichang.processor.matedata.TableInfo;

View File

@ -1,6 +1,6 @@
package com.github.yulichang.processor.matedata; package com.github.yulichang.processor.matedata;
import com.github.yulichang.apt.OgnlRoot; import com.github.yulichang.extension.apt.matedata.OgnlRoot;
import org.apache.ibatis.builder.BuilderException; import org.apache.ibatis.builder.BuilderException;
import org.apache.ibatis.ognl.Ognl; import org.apache.ibatis.ognl.Ognl;
import org.apache.ibatis.ognl.OgnlContext; import org.apache.ibatis.ognl.OgnlContext;