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
99dc3b0f9c
commit
d0e99f0313
@ -2,6 +2,7 @@ package com.github.yulichang.interceptor;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
|
||||
import com.github.yulichang.method.MPJResultType;
|
||||
import com.github.yulichang.toolkit.Constant;
|
||||
import org.apache.ibatis.executor.Executor;
|
||||
import org.apache.ibatis.mapping.BoundSql;
|
||||
@ -14,6 +15,7 @@ import java.lang.reflect.Field;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 结果封装拦截器
|
||||
@ -41,10 +43,14 @@ public class MPJInterceptor implements InnerInterceptor {
|
||||
if (CollectionUtils.isNotEmpty(map)) {
|
||||
try {
|
||||
Class<?> clazz = (Class<?>) map.get(Constant.CLAZZ);
|
||||
List<ResultMap> list = ms.getResultMaps();
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
ResultMap resultMap = list.get(0);
|
||||
type.set(resultMap, clazz);
|
||||
if (Objects.nonNull(clazz)) {
|
||||
List<ResultMap> list = ms.getResultMaps();
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
ResultMap resultMap = list.get(0);
|
||||
if (resultMap.getType() == MPJResultType.class) {
|
||||
type.set(resultMap, clazz);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
//通常是MapperMethod内部类HashMap的子类ParamMap重写了了get方法抛出的BindingException
|
||||
|
11
src/main/java/com/github/yulichang/method/MPJResultType.java
Normal file
11
src/main/java/com/github/yulichang/method/MPJResultType.java
Normal file
@ -0,0 +1,11 @@
|
||||
package com.github.yulichang.method;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* result type 标识类
|
||||
*
|
||||
* @author yulichang
|
||||
*/
|
||||
public class MPJResultType implements Serializable {
|
||||
}
|
@ -17,6 +17,6 @@ public class SelectJoinList extends MPJAbstractMethod {
|
||||
String sql = String.format(sqlMethod.getSql(), sqlFirst(), sqlSelectColumns(tableInfo, true),
|
||||
tableInfo.getTableName(), sqlAlias(), sqlFrom(), sqlWhereEntityWrapper(true, tableInfo), sqlComment());
|
||||
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
|
||||
return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, Object.class);
|
||||
return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, MPJResultType.class);
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,6 @@ public class SelectJoinOne extends MPJAbstractMethod {
|
||||
String sql = String.format(sqlMethod.getSql(), sqlFirst(), sqlSelectColumns(tableInfo, true),
|
||||
tableInfo.getTableName(), sqlAlias(), sqlFrom(), sqlWhereEntityWrapper(true, tableInfo), sqlComment());
|
||||
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
|
||||
return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, Object.class);
|
||||
return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, MPJResultType.class);
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,6 @@ public class SelectJoinPage extends MPJAbstractMethod {
|
||||
String sql = String.format(sqlMethod.getSql(), sqlFirst(), sqlSelectColumns(tableInfo, true),
|
||||
tableInfo.getTableName(), sqlAlias(), sqlFrom(), sqlWhereEntityWrapper(true, tableInfo), sqlComment());
|
||||
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
|
||||
return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, Object.class);
|
||||
return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, MPJResultType.class);
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public interface Constant {
|
||||
|
||||
String INNER = "INNER";
|
||||
|
||||
String CLAZZ = "clazz";
|
||||
String CLAZZ = "resultTypeClass_Eg1sG";
|
||||
|
||||
/**
|
||||
* " LEFT JOIN "
|
||||
|
@ -18,6 +18,7 @@ public class Wrappers {
|
||||
return new MPJQueryWrapper<>();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static <T> MPJLambdaQueryWrapper<T> lambdaJoin() {
|
||||
return new MPJLambdaQueryWrapper<>();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user