Parcourir la source

格式化数据库换行注释.

https://github.com/baomidou/mybatis-plus/issues/2498
nieqiuqiu il y a 5 ans
Parent
commit
51429aa102

+ 14 - 2
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/ConfigBuilder.java

@@ -502,7 +502,7 @@ public class ConfigBuilder {
                                 // 跳过视图
                                 continue;
                             }
-                            tableInfo.setComment(tableComment);
+                            tableInfo.setComment(formatComment(tableComment));
                         }
 
                         if (isInclude) {
@@ -674,7 +674,7 @@ public class ConfigBuilder {
                     }
                     field.setColumnType(dataSourceConfig.getTypeConvert().processTypeConvert(globalConfig, field));
                     if (commentSupported) {
-                        field.setComment(results.getString(dbQuery.fieldComment()));
+                        field.setComment(formatComment(results.getString(dbQuery.fieldComment())));
                     }
                     // 填充逻辑判断
                     List<TableFill> tableFillList = getStrategyConfig().getTableFillList();
@@ -808,4 +808,16 @@ public class ConfigBuilder {
         this.injectionConfig = injectionConfig;
         return this;
     }
+
+    /**
+     * 格式化数据库注释内容
+     *
+     * @param comment 注释
+     * @return 注释
+     * @since 3.3.3
+     */
+    public String formatComment(String comment) {
+        return StringUtils.isBlank(comment) ? StringPool.EMPTY : comment.replaceAll("\r\n", "\t");
+    }
+
 }

+ 1 - 1
mybatis-plus-generator/src/main/resources/templates/entity.java.vm

@@ -49,7 +49,7 @@ public class ${entity} implements Serializable {
 #end
 
 #if(${entitySerialVersionUID})
-    private static final long serialVersionUID=1L;
+    private static final long serialVersionUID = 1L;
 #end
 ## ----------  BEGIN 字段循环遍历  ----------
 #foreach($field in ${table.fields})