代码生成器
依赖包
<!--代码生成插件-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.1.1</version>
</dependency>
<!--freemarker支持-->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.28</version>
</dependency>
执行程序
package com.wafersystems.virsical.map;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* 代码生成,执行 main 方法控制台输入模块表名回车自动生成对应项目目录中
*
* @author tandk
* @date 2019/4/30 10:57
*/
@Slf4j
@UtilityClass
public class CodeGenerator {
/**
* 如果模板引擎是 freemarker
*/
private final String templatePath = "/templates/mapper.xml.ftl";
/**
* <p>
* 读取控制台内容
* </p>
*/
public static String scanner(String tip) {
Scanner scanner = new Scanner(System.in, "UTF-8");
StringBuilder help = new StringBuilder();
help.append("请输入" + tip + ":");
log.info(help.toString());
if (scanner.hasNext()) {
String ipt = scanner.next();
if (StringUtils.isNotEmpty(ipt)) {
return ipt;
}
}
throw new MybatisPlusException("请输入正确的" + tip + "!");
}
/**
* 代码生成入口
*/
public static void main(String[] args) {
// 全局配置
GlobalConfig gc = new GlobalConfig();
String projectPath = System.