method 代码同步 3.5.x

This commit is contained in:
yulichang 2022-11-06 23:54:24 +08:00
parent 333230f7da
commit 00311e5dda
19 changed files with 169 additions and 34 deletions

View File

@ -45,13 +45,6 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>

View File

@ -1,16 +1,13 @@
package com.github.yulichang.config;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInterceptor;
import com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration;
import com.github.yulichang.interceptor.MPJInterceptor;
import com.github.yulichang.toolkit.InterceptorList;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.InterceptorChain;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Configuration;
@ -24,7 +21,6 @@ import java.util.List;
*/
@Configuration
@ConditionalOnBean(SqlSessionFactory.class)
@AutoConfigureBefore(value = {PageHelper.class, PageHelperAutoConfiguration.class, PageInterceptor.class})
@SuppressWarnings("unused")
public class InterceptorConfig {
@ -53,6 +49,7 @@ public class InterceptorConfig {
} else {
interceptors.set(chain, new InterceptorList<>(list));
}
chain.addInterceptor(new MPJInterceptor());
} catch (NoSuchFieldException | IllegalAccessException e) {
logger.error("初始化 MPJ 拦截器失败");
e.printStackTrace();

View File

@ -1,23 +1,15 @@
package com.github.yulichang.injector;
import com.baomidou.mybatisplus.core.MybatisPlusVersion;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.AbstractSqlInjector;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.core.injector.methods.Delete;
import com.baomidou.mybatisplus.core.injector.methods.DeleteById;
import com.baomidou.mybatisplus.core.injector.methods.DeleteByMap;
import com.baomidou.mybatisplus.core.injector.methods.Insert;
import com.baomidou.mybatisplus.core.injector.methods.DeleteBatchByIds;
import com.baomidou.mybatisplus.core.injector.methods.SelectById;
import com.baomidou.mybatisplus.core.injector.methods.Update;
import com.baomidou.mybatisplus.core.injector.methods.UpdateById;
import com.baomidou.mybatisplus.core.injector.methods.SelectBatchByIds;
import com.baomidou.mybatisplus.core.injector.methods.SelectByMap;
import com.baomidou.mybatisplus.core.injector.methods.*;
import com.baomidou.mybatisplus.core.mapper.Mapper;
import com.github.yulichang.mapper.MPJTableMapperHelper;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
import com.github.yulichang.mapper.MPJTableMapperHelper;
import com.github.yulichang.method.*;
import com.github.yulichang.method.mp.SelectCount;
import com.github.yulichang.method.mp.SelectList;
@ -89,13 +81,28 @@ public class MPJSqlInjector extends DefaultSqlInjector {
private List<AbstractMethod> getJoinMethod() {
List<AbstractMethod> list = new ArrayList<>();
list.add(new SelectJoinCount());
list.add(new SelectJoinOne());
list.add(new SelectJoinList());
list.add(new SelectJoinPage());
list.add(new SelectJoinMap());
list.add(new SelectJoinMaps());
list.add(new SelectJoinMapsPage());
String version = MybatisPlusVersion.getVersion();
String[] split = version.split("\\.");
int v1 = Integer.parseInt(split[0]);
int v2 = Integer.parseInt(split[1]);
if ((v1 == 3 && v2 >= 5) || v1 > 3) {
list.add(new SelectJoinCount(SqlMethod.SELECT_JOIN_COUNT.getMethod()));
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 SelectJoinCount());
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;
}

View File

@ -15,6 +15,18 @@ import java.util.List;
*/
public abstract class MPJAbstractMethod extends AbstractMethod implements MPJBaseMethod {
@Deprecated
@SuppressWarnings("DeprecatedIsStillUsed")
public MPJAbstractMethod() {
super();
}
@SuppressWarnings({"unused", "deprecation"})
protected MPJAbstractMethod(String methodName) {
super();
}
/**
* 连表操作不考虑entity查询和逻辑删除
*/

View File

@ -12,6 +12,16 @@ import org.apache.ibatis.mapping.SqlSource;
*/
public class SelectJoinCount extends MPJAbstractMethod {
@SuppressWarnings("deprecation")
public SelectJoinCount() {
super();
}
@SuppressWarnings("unused")
public SelectJoinCount(String name) {
super(name);
}
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
SqlMethod sqlMethod = SqlMethod.SELECT_JOIN_COUNT;

View File

@ -11,6 +11,15 @@ import org.apache.ibatis.mapping.SqlSource;
*/
public class SelectJoinList extends MPJAbstractMethod {
public SelectJoinList() {
super(SqlMethod.SELECT_JOIN_LIST.getMethod());
}
@SuppressWarnings("unused")
public SelectJoinList(String name) {
super(name);
}
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
SqlMethod sqlMethod = SqlMethod.SELECT_JOIN_LIST;

View File

@ -13,6 +13,15 @@ import java.util.Map;
*/
public class SelectJoinMap extends MPJAbstractMethod {
public SelectJoinMap() {
super(SqlMethod.SELECT_JOIN_LIST.getMethod());
}
@SuppressWarnings("unused")
public SelectJoinMap(String name) {
super(name);
}
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
SqlMethod sqlMethod = SqlMethod.SELECT_JOIN_MAP;

View File

@ -13,6 +13,15 @@ import java.util.Map;
*/
public class SelectJoinMaps extends MPJAbstractMethod {
public SelectJoinMaps() {
super(SqlMethod.SELECT_JOIN_MAPS.getMethod());
}
@SuppressWarnings("unused")
public SelectJoinMaps(String name) {
super(name);
}
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
SqlMethod sqlMethod = SqlMethod.SELECT_JOIN_MAPS;

View File

@ -13,6 +13,15 @@ import java.util.Map;
*/
public class SelectJoinMapsPage extends MPJAbstractMethod {
public SelectJoinMapsPage() {
super(SqlMethod.SELECT_JOIN_MAPS_PAGE.getMethod());
}
@SuppressWarnings("unused")
public SelectJoinMapsPage(String name) {
super(name);
}
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
SqlMethod sqlMethod = SqlMethod.SELECT_JOIN_MAPS_PAGE;

View File

@ -11,6 +11,15 @@ import org.apache.ibatis.mapping.SqlSource;
*/
public class SelectJoinOne extends MPJAbstractMethod {
public SelectJoinOne() {
super(SqlMethod.SELECT_JOIN_ONE.getMethod());
}
@SuppressWarnings("unused")
public SelectJoinOne(String name) {
super(name);
}
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
SqlMethod sqlMethod = SqlMethod.SELECT_JOIN_ONE;

View File

@ -11,6 +11,15 @@ import org.apache.ibatis.mapping.SqlSource;
*/
public class SelectJoinPage extends MPJAbstractMethod {
public SelectJoinPage() {
super(SqlMethod.SELECT_JOIN_PAGE.getMethod());
}
@SuppressWarnings("unused")
public SelectJoinPage(String name) {
super(name);
}
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
SqlMethod sqlMethod = SqlMethod.SELECT_JOIN_PAGE;

View File

@ -11,6 +11,15 @@ import org.apache.ibatis.mapping.MappedStatement;
*/
public class SelectCount extends com.baomidou.mybatisplus.core.injector.methods.SelectCount implements TableAlias {
public SelectCount() {
super();
}
@SuppressWarnings("unused")
public SelectCount(String name) {
super(name);
}
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
return super.injectMappedStatement(mapperClass, modelClass,

View File

@ -12,6 +12,15 @@ import org.apache.ibatis.mapping.MappedStatement;
*/
public class SelectList extends com.baomidou.mybatisplus.core.injector.methods.SelectList implements TableAlias {
public SelectList() {
super();
}
@SuppressWarnings("unused")
public SelectList(String name) {
super(name);
}
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
return super.injectMappedStatement(mapperClass, modelClass,

View File

@ -12,6 +12,15 @@ import org.apache.ibatis.mapping.MappedStatement;
*/
public class SelectMaps extends com.baomidou.mybatisplus.core.injector.methods.SelectMaps implements TableAlias {
public SelectMaps() {
super();
}
@SuppressWarnings("unused")
public SelectMaps(String name) {
super(name);
}
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
return super.injectMappedStatement(mapperClass, modelClass,

View File

@ -12,6 +12,15 @@ import org.apache.ibatis.mapping.MappedStatement;
*/
public class SelectMapsPage extends com.baomidou.mybatisplus.core.injector.methods.SelectMapsPage implements TableAlias {
public SelectMapsPage() {
super();
}
@SuppressWarnings("unused")
public SelectMapsPage(String name) {
super(name);
}
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
return super.injectMappedStatement(mapperClass, modelClass,

View File

@ -12,6 +12,15 @@ import org.apache.ibatis.mapping.MappedStatement;
*/
public class SelectObjs extends com.baomidou.mybatisplus.core.injector.methods.SelectObjs implements TableAlias {
public SelectObjs() {
super();
}
@SuppressWarnings("unused")
public SelectObjs(String name) {
super(name);
}
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
return super.injectMappedStatement(mapperClass, modelClass,

View File

@ -17,6 +17,15 @@ import org.apache.ibatis.mapping.MappedStatement;
@SuppressWarnings("deprecation")
public class SelectOne extends com.baomidou.mybatisplus.core.injector.methods.SelectOne implements TableAlias {
public SelectOne() {
super();
}
@SuppressWarnings("unused")
public SelectOne(String name) {
super(name);
}
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
return super.injectMappedStatement(mapperClass, modelClass,

View File

@ -12,6 +12,15 @@ import org.apache.ibatis.mapping.MappedStatement;
*/
public class SelectPage extends com.baomidou.mybatisplus.core.injector.methods.SelectPage implements TableAlias {
public SelectPage() {
super();
}
@SuppressWarnings("unused")
public SelectPage(String name) {
super(name);
}
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
return super.injectMappedStatement(mapperClass, modelClass,

View File

@ -36,14 +36,13 @@ public class InterceptorList<E extends Interceptor> extends ArrayList<E> {
if (this.isEmpty()) {
return super.add(e);
}
boolean add = super.add(e);
Predicate<E> predicate = i -> i instanceof MPJInterceptor;
if (this.stream().anyMatch(predicate)) {
E mpjInterceptor = super.stream().filter(predicate).findFirst().orElse(null);
super.removeIf(predicate);
boolean a = super.add(e);
boolean b = super.add(mpjInterceptor);
return a && b;
return super.add(mpjInterceptor);
}
return super.add(e);
return add;
}
}