|
@@ -18,19 +18,18 @@ import java.util.Scanner;
|
|
|
|
|
|
/**
|
|
/**
|
|
* mybatis-plus代码生成器
|
|
* mybatis-plus代码生成器
|
|
- * 使用该类需要添加以下依赖,在此之前请移除所有与mybatis有关的其他依赖,防止冲突
|
|
|
|
- * <dependency>
|
|
|
|
- * <groupId>com.baomidou</groupId>
|
|
|
|
- * <artifactId>mybatis-plus-generator</artifactId>
|
|
|
|
- * <version>3.1.2</version>
|
|
|
|
- * </dependency>
|
|
|
|
- *
|
|
|
|
- * <dependency>
|
|
|
|
- * <groupId>com.baomidou</groupId>
|
|
|
|
- * <artifactId>mybatis-plus-boot-starter</artifactId>
|
|
|
|
- * <version>3.1.2</version>
|
|
|
|
- * </dependency>
|
|
|
|
|
|
+ * 使用该类需要添加以下依赖,在此之前请移除所有与mybatis有关的其他依赖,防止冲突
|
|
|
|
+ * <dependency>
|
|
|
|
+ * <groupId>com.baomidou</groupId>
|
|
|
|
+ * <artifactId>mybatis-plus-generator</artifactId>
|
|
|
|
+ * <version>3.1.2</version>
|
|
|
|
+ * </dependency>
|
|
*
|
|
*
|
|
|
|
+ * <dependency>
|
|
|
|
+ * <groupId>com.baomidou</groupId>
|
|
|
|
+ * <artifactId>mybatis-plus-boot-starter</artifactId>
|
|
|
|
+ * <version>3.1.2</version>
|
|
|
|
+ * </dependency>
|
|
*/
|
|
*/
|
|
// 演示例子,执行 main 方法控制台输入模块表名回车自动生成对应项目目录中
|
|
// 演示例子,执行 main 方法控制台输入模块表名回车自动生成对应项目目录中
|
|
public class CodeGenerator {
|
|
public class CodeGenerator {
|
|
@@ -131,7 +130,7 @@ public class CodeGenerator {
|
|
* <version>2.0</version>
|
|
* <version>2.0</version>
|
|
* </dependency>
|
|
* </dependency>
|
|
*/
|
|
*/
|
|
- String templatePath = "/templates/mapper.xml.vm";
|
|
|
|
|
|
+ String templatePath = "/templates/mapper.xml.vm";
|
|
|
|
|
|
// 自定义输出配置
|
|
// 自定义输出配置
|
|
List<FileOutConfig> focList = new ArrayList<>();
|
|
List<FileOutConfig> focList = new ArrayList<>();
|
|
@@ -139,10 +138,10 @@ public class CodeGenerator {
|
|
focList.add(new FileOutConfig(templatePath) {
|
|
focList.add(new FileOutConfig(templatePath) {
|
|
@Override
|
|
@Override
|
|
public String outputFile(TableInfo tableInfo) {
|
|
public String outputFile(TableInfo tableInfo) {
|
|
- if(pc.getModuleName() == null){
|
|
|
|
|
|
+ if (pc.getModuleName() == null) {
|
|
return projectPath + "/src/main/resources/mapper/"
|
|
return projectPath + "/src/main/resources/mapper/"
|
|
+ tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
|
|
+ tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
|
|
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
|
|
return projectPath + "/src/main/resources/mapper/" + pc.getModuleName()
|
|
return projectPath + "/src/main/resources/mapper/" + pc.getModuleName()
|
|
+ "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
|
|
+ "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
|
|
@@ -160,15 +159,15 @@ public class CodeGenerator {
|
|
//对于已存在的文件,只需重复生成 entity 和 mapper.xml
|
|
//对于已存在的文件,只需重复生成 entity 和 mapper.xml
|
|
File file = new File(filePath);
|
|
File file = new File(filePath);
|
|
boolean exist = file.exists();
|
|
boolean exist = file.exists();
|
|
- if(exist){
|
|
|
|
- if (filePath.endsWith("Mapper.xml")||FileType.ENTITY==fileType){
|
|
|
|
|
|
+ if (exist) {
|
|
|
|
+ if (filePath.endsWith("Mapper.xml") || FileType.ENTITY == fileType) {
|
|
return true;
|
|
return true;
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//不存在的文件都需要创建
|
|
//不存在的文件都需要创建
|
|
- return true;
|
|
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
@@ -206,7 +205,7 @@ public class CodeGenerator {
|
|
//此处user是表名,多个英文逗号分割
|
|
//此处user是表名,多个英文逗号分割
|
|
// strategy.setInclude("mould_down_packet");
|
|
// strategy.setInclude("mould_down_packet");
|
|
// strategy.setExclude();//数据库表全生成
|
|
// strategy.setExclude();//数据库表全生成
|
|
- strategy.setInclude("characteristic");//表名,多个英文逗号分割
|
|
|
|
|
|
+ strategy.setInclude();//表名,多个英文逗号分割
|
|
strategy.setControllerMappingHyphenStyle(true);
|
|
strategy.setControllerMappingHyphenStyle(true);
|
|
//数据库表前缀,不配置这行的话,生成的类会带有T如:TUser,配置后即可将前缀去掉
|
|
//数据库表前缀,不配置这行的话,生成的类会带有T如:TUser,配置后即可将前缀去掉
|
|
// strategy.setTablePrefix("tb_");
|
|
// strategy.setTablePrefix("tb_");
|