|
@@ -23,8 +23,6 @@ import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
|
|
|
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
|
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.sql.SqlHelper;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.support.Property;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.support.SerializedLambda;
|
|
|
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
|
|
import org.apache.ibatis.executor.keygen.KeyGenerator;
|
|
|
import org.apache.ibatis.executor.keygen.NoKeyGenerator;
|
|
@@ -40,7 +38,10 @@ import org.apache.ibatis.session.Configuration;
|
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
/**
|
|
@@ -68,71 +69,6 @@ public class TableInfoHelper {
|
|
|
*/
|
|
|
private static final String DEFAULT_ID_NAME = "id";
|
|
|
|
|
|
- /**
|
|
|
- * @param func 需要进行转换的 func
|
|
|
- * @param <T> 被函数调用的类型,这个必须指定
|
|
|
- * @return 返回解析后的列名
|
|
|
- */
|
|
|
- public static <T> String toColumn(Property<T, ?> func) {//todo 只需要返回className以及methodName,放到lamWrapper里根据缓存取出columnName
|
|
|
- SerializedLambda lambda = LambdaUtils.resolve(func);
|
|
|
- // 使用 class 名称和方法名称作为缓存的键值
|
|
|
- String cacheKey = lambda.getImplClass() + lambda.getImplMethodName();
|
|
|
- return Optional.ofNullable(LAMBDA_COLUMN_CACHE.get(cacheKey))
|
|
|
- .orElseGet(() -> {
|
|
|
- String column = resolveColumn(lambda);
|
|
|
- LAMBDA_COLUMN_CACHE.put(cacheKey, column);
|
|
|
- return column;
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param lambda 需要解析的 column
|
|
|
- * @return 返回解析后列的信息
|
|
|
- */
|
|
|
- private static String resolveColumn(SerializedLambda lambda) {
|
|
|
- String filedName = resolveFieldName(lambda);
|
|
|
- return filedName;
|
|
|
- // 为防止后面字段,驼峰等信息根据配置发生变化,此处不自己解析字段信息
|
|
|
-// return getTableInfo(resolveClass(lambda)).getFieldList().stream()
|
|
|
-// .filter(fieldInfo -> filedName.equals(fieldInfo.getProperty()))
|
|
|
-// .findAny()
|
|
|
-// .map(TableFieldInfo::getColumn)
|
|
|
-// .orElseThrow(() -> {
|
|
|
-// String message = String.format("没有根据 %s#%s 解析到对应的表列名称,您可能排除了该字段或者 %s 方法不是标准的 getter 方法"
|
|
|
-// , lambda.getImplClass(), lambda.getImplMethodName(), lambda.getImplMethodName());
|
|
|
-// return new MybatisPlusException(message);
|
|
|
-// });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param lambda 需要解析的 lambda
|
|
|
- * @return 返回解析后的字段名称
|
|
|
- */
|
|
|
- private static String resolveFieldName(SerializedLambda lambda) {
|
|
|
- String name = lambda.getImplMethodName();
|
|
|
- if (name.startsWith("get")) {
|
|
|
- name = name.substring(3, name.length());
|
|
|
- } else if (name.startsWith("is")) {
|
|
|
- name = name.substring(2, name.length());
|
|
|
- }
|
|
|
- // 小写第一个字母
|
|
|
- return StringUtils.firstToLowerCase(name);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param lambda 需要解析的 lambda
|
|
|
- * @return 返回解析后的class
|
|
|
- */
|
|
|
- @Deprecated
|
|
|
- private static Class<?> resolveClass(SerializedLambda lambda) {
|
|
|
- String className = lambda.getImplClass().replace('/', '.');
|
|
|
- try {
|
|
|
- return Class.forName(className);
|
|
|
- } catch (ClassNotFoundException e) { // 这个异常不可能发生
|
|
|
- throw new MybatisPlusException("Class : " + className + " 不存在?你是怎么调用的?", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* <p>
|
|
|
* 获取实体映射表信息
|