From fcf75f58122430c9a77a1b3edb262f83c6c08bc5 Mon Sep 17 00:00:00 2001 From: Jayce Date: Mon, 15 Jan 2018 15:04:11 +0800 Subject: [PATCH] bug fix --- .../baomidou/config/rules/NamingStrategy.java | 13 ++--- src/main/resources/template/entity.java.vm | 48 +++++++++---------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/baomidou/config/rules/NamingStrategy.java b/src/main/java/com/baomidou/config/rules/NamingStrategy.java index 72bc9cc..ac90cfe 100644 --- a/src/main/java/com/baomidou/config/rules/NamingStrategy.java +++ b/src/main/java/com/baomidou/config/rules/NamingStrategy.java @@ -77,15 +77,16 @@ public enum NamingStrategy { * @return */ public static String removePrefix(String name, String prefix) { - if (StringUtils.isBlank(name)) { + if (StringUtils.isBlank(name)) { return ""; } - int idx = name.indexOf(ConstVal.UNDERLINE); - if(prefix != null && !"".equals(prefix.trim())) { - if(name.toLowerCase().matches("^" + prefix.toLowerCase() + ".*")) { // 判断是否有匹配的前缀,然后截取前缀 - idx = prefix.length() - 1; + int idx = -1; + if (prefix != null && !"".equals(prefix.trim())) { + idx = name.indexOf(ConstVal.UNDERLINE); + if (name.toLowerCase().matches("^" + prefix.toLowerCase() + ".*")) { // 判断是否有匹配的前缀,然后截取前缀 + idx = prefix.length() - 1; } - } + } if (idx == -1) { return name; } diff --git a/src/main/resources/template/entity.java.vm b/src/main/resources/template/entity.java.vm index 69eee6e..16299e4 100644 --- a/src/main/resources/template/entity.java.vm +++ b/src/main/resources/template/entity.java.vm @@ -4,7 +4,7 @@ package ${package.Entity}; import com.baomidou.mybatisplus.activerecord.Model; #end #if(${idGenType}!="ID_WORKER") -import com.baomidou.mybatisplus.annotations.IdType; +import com.baomidou.mybatisplus.enums.IdType; import com.baomidou.mybatisplus.annotations.TableId; #end import com.baomidou.mybatisplus.annotations.TableField; @@ -33,36 +33,36 @@ public class ${entity} extends Model<${entity}> { public class ${entity} implements Serializable { #end - private static final long serialVersionUID = 1L; +private static final long serialVersionUID = 1L; #foreach($field in ${table.fields}) - /** - * ${field.comment} - */ -#if(${field.keyFlag} && ${idGenType}!="ID_WORKER") - @TableId(type = IdType.${idGenType}) -#end -#if($field.convert && ${field.name.toLowerCase()} != ${field.propertyName.toLowerCase()}) - @TableField(value="${field.name}") -#end - private ${field.propertyType} ${field.propertyName}; +/** + * ${field.comment} + */ + #if(${field.keyFlag} && ${idGenType}!="ID_WORKER") + @TableId(type = IdType.${idGenType}) + #end + #if($field.convert && ${field.name.toLowerCase()} != ${field.propertyName.toLowerCase()}) + @TableField(value="${field.name}") + #end +private ${field.propertyType} ${field.propertyName}; #end #foreach($field in ${table.fields}) -#if(${field.propertyName.equals("Boolean")}) -#set($getprefix="is") -#else -#set($getprefix="get") -#end + #if(${field.propertyName.equals("Boolean")}) + #set($getprefix="is") + #else + #set($getprefix="get") + #end - public ${field.propertyType} ${getprefix}${field.capitalName}() { - return ${field.propertyName}; - } +public ${field.propertyType} ${getprefix}${field.capitalName}() { + return ${field.propertyName}; + } - public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) { - this.${field.propertyName} = ${field.propertyName}; - } +public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) { + this.${field.propertyName} = ${field.propertyName}; + } #end -} + } -- Gitee