Преглед изворни кода

# WARNING: head commit changed in the meantime

Merge branch 'dev' of https://git.oschina.net/baomidou/mybatis-plus.git
into dev

Conflicts:
	src/main/java/com/baomidou/mybatisplus/generator/AutoGenerator.java
willenfoo пре 8 година
родитељ
комит
1363c00855

+ 5 - 0
src/main/java/com/baomidou/mybatisplus/generator/AutoGenerator.java

@@ -131,6 +131,10 @@ public class AutoGenerator extends AbstractGenerator {
                 // 表注解
                 // 表注解
                 tableInfo.setImportPackages("com.baomidou.mybatisplus.annotations.TableName");
                 tableInfo.setImportPackages("com.baomidou.mybatisplus.annotations.TableName");
             }
             }
+            if (tableInfo.isLogicDelete(config.getGlobalConfig().getLogicDeletePropertyName())) {
+                // 逻辑删除注解
+            	tableInfo.setImportPackages("com.baomidou.mybatisplus.annotations.TableLogic");
+            }
             if (StringUtils.isNotEmpty(config.getSuperEntityClass())) {
             if (StringUtils.isNotEmpty(config.getSuperEntityClass())) {
                 // 父实体
                 // 父实体
                 tableInfo.setImportPackages(config.getSuperEntityClass());
                 tableInfo.setImportPackages(config.getSuperEntityClass());
@@ -159,6 +163,7 @@ public class AutoGenerator extends AbstractGenerator {
             ctx.put("restControllerStyle", config.getStrategyConfig().isRestControllerStyle());
             ctx.put("restControllerStyle", config.getStrategyConfig().isRestControllerStyle());
             ctx.put("package", packageInfo);
             ctx.put("package", packageInfo);
             ctx.put("author", config.getGlobalConfig().getAuthor());
             ctx.put("author", config.getGlobalConfig().getAuthor());
+            ctx.put("logicDeletePropertyName", config.getGlobalConfig().getLogicDeletePropertyName());
             ctx.put("activeRecord", config.getGlobalConfig().isActiveRecord());
             ctx.put("activeRecord", config.getGlobalConfig().isActiveRecord());
             ctx.put("date", date);
             ctx.put("date", date);
             ctx.put("table", tableInfo);
             ctx.put("table", tableInfo);

+ 13 - 0
src/main/java/com/baomidou/mybatisplus/generator/config/GlobalConfig.java

@@ -73,6 +73,11 @@ public class GlobalConfig {
     private String serviceImplName;
     private String serviceImplName;
     private String controllerName;
     private String controllerName;
 
 
+    /**
+     * 逻辑删除属性名称
+     */
+    private String logicDeletePropertyName;
+    
     public String getOutputDir() {
     public String getOutputDir() {
         return outputDir;
         return outputDir;
     }
     }
@@ -177,4 +182,12 @@ public class GlobalConfig {
         this.controllerName = controllerName;
         this.controllerName = controllerName;
     }
     }
 
 
+	public String getLogicDeletePropertyName() {
+		return logicDeletePropertyName;
+	}
+
+	public void setLogicDeletePropertyName(String logicDeletePropertyName) {
+		this.logicDeletePropertyName = logicDeletePropertyName;
+	}
+
 }
 }

+ 12 - 0
src/main/java/com/baomidou/mybatisplus/generator/config/po/TableInfo.java

@@ -200,6 +200,18 @@ public class TableInfo {
         importPackages.add(pkg);
         importPackages.add(pkg);
     }
     }
 
 
+    /**
+     * 逻辑删除
+     */
+    public boolean isLogicDelete(String logicDeletePropertyName) {
+    	for (TableField tableField : fields) {
+			if (tableField.getPropertyName().equals(logicDeletePropertyName)) {
+				return true;
+			}
+		}
+		return false;
+	}
+    
     /**
     /**
      * 转换filed实体为xmlmapper中的basecolumn字符串信息
      * 转换filed实体为xmlmapper中的basecolumn字符串信息
      *
      *

+ 3 - 0
src/main/resources/templates/entity.java.vm

@@ -50,6 +50,9 @@ public class ${entity} implements Serializable {
 #end
 #end
 #elseif(${field.convert})
 #elseif(${field.convert})
 	@TableField("${field.name}")
 	@TableField("${field.name}")
+#end
+#if(${logicDeletePropertyName}==${field.propertyName})
+    @TableLogic
 #end
 #end
 	private ${field.propertyType} ${field.propertyName};
 	private ${field.propertyType} ${field.propertyName};
 #end
 #end