Forráskód Böngészése

新增自动构建 resultMap 功能,去除转义符

miemie 6 éve
szülő
commit
439a970d34

+ 3 - 3
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/TableInfo.java

@@ -337,7 +337,7 @@ public class TableInfo implements Constants {
      */
     public void initResultMapIfNeed() {
         if (StringUtils.isEmpty(resultMap)) {
-            String id = currentNamespace + DOT + MYBATIS_PLUS + UNDERSCORE + entityType.getName();
+            String id = currentNamespace + DOT + MYBATIS_PLUS + UNDERSCORE + entityType.getSimpleName();
             List<ResultMapping> resultMappings = new ArrayList<>();
             if (keyType != null) {
                 ResultMapping idMapping = new ResultMapping.Builder(configuration, keyProperty, keyColumn, keyType)
@@ -346,8 +346,8 @@ public class TableInfo implements Constants {
             }
             if (CollectionUtils.isNotEmpty(fieldList)) {
                 fieldList.forEach(f -> {
-                    ResultMapping mapping = new ResultMapping.Builder(configuration, f.getProperty(), f.getColumn(),
-                        f.getPropertyType()).build();
+                    ResultMapping mapping = new ResultMapping.Builder(configuration, f.getProperty(),
+                        StringUtils.getTargetColumn(f.getColumn()), f.getPropertyType()).build();
                     resultMappings.add(mapping);
                 });
             }

+ 14 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/StringUtils.java

@@ -159,6 +159,19 @@ public class StringUtils {
         return !P_IS_COLUMN.matcher(str).matches();
     }
 
+    /**
+     * 获取真正的字段名
+     *
+     * @param column 字段名
+     * @return 字段名
+     */
+    public static String getTargetColumn(String column) {
+        if (isNotColumnName(column)) {
+            return column.substring(1, column.length() - 1);
+        }
+        return column;
+    }
+
     /**
      * 字符串驼峰转下划线格式
      *
@@ -813,8 +826,8 @@ public class StringUtils {
      *
      * @param s 原字符串
      * @param p 移除的单词
-     * @deprecated 3.1.1
      * @return ignore
+     * @deprecated 3.1.1
      */
     @Deprecated
     public static String removeWordWithComma(String s, String p) {