admin 2021-03-26 09:53:52 +08:00
parent 99dc3b0f9c
commit d0e99f0313
7 changed files with 26 additions and 8 deletions

View File

@ -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

View File

@ -0,0 +1,11 @@
package com.github.yulichang.method;
import java.io.Serializable;
/**
* result type 标识类
*
* @author yulichang
*/
public class MPJResultType implements Serializable {
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -25,7 +25,7 @@ public interface Constant {
String INNER = "INNER";
String CLAZZ = "clazz";
String CLAZZ = "resultTypeClass_Eg1sG";
/**
* " LEFT JOIN "

View File

@ -18,6 +18,7 @@ public class Wrappers {
return new MPJQueryWrapper<>();
}
@Deprecated
public static <T> MPJLambdaQueryWrapper<T> lambdaJoin() {
return new MPJLambdaQueryWrapper<>();
}