web123456

mybatis-plus code generator

  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • /**
  • * @Description:
  • * @Auther: chenmingjian
  • * @Date: 18-10-25 18:14
  • */
  • public class CodeGenerator {
  • //Code Generator
  • private static AutoGenerator mpg = new AutoGenerator();
  • //Global configuration
  • private static GlobalConfig gc = new GlobalConfig();
  • //Author, package name, remove table prefix
  • private static final String author = "chenmingjian";
  • private static final String package_name = "mybatisplus";
  • private static final String TABLE_PREFIX = "tb_";
  • //database
  • private static final String url = "jdbc:mysql://192.168.3.172:3306/test?useUnicode=true&useSSL=false&characterEncoding=utf8";
  • private static final String driverName = "";
  • private static final String userName = "devuser";
  • private static final String password = "dev123";
  • private static final String table_name = "tb_user";
  • public static void main(String[] args){
  • // Data source configuration
  • setDataSource();
  • // Global configuration
  • setGlobalConfig();
  • // Policy configuration
  • setStrategy();
  • //implement
  • ();
  • }
  • private static void setStrategy() {
  • StrategyConfig strategy = new StrategyConfig();
  • // Class name: Tb_userController -> TbUserController
  • (NamingStrategy.underline_to_camel);
  • // Attribute name: start_time -> startTime
  • (NamingStrategy.underline_to_camel);
  • // lombok instead of setter/getter and other methods
  • (true);
  • // Set Controller to RestController
  • (true);
  • // Generate from the database table
  • (table_name);
  • //Remove the table prefix
  • (TABLE_PREFIX);
  • (strategy);
  • }
  • private static void setGlobalConfig() {
  • URL urlPath = ().getContextClassLoader().getResource("");
  • String projectPath = (urlPath).getPath().replace("target/classes", "src/main/java");
  • (projectPath);//Code generation location
  • (true);//Overwrite existing files
  • (author);
  • gc.setSwagger2(true);
  • ();// Primary key ID type
  • (DateType.ONLY_DATE);//Set the time type to Date
  • (gc);
  • PackageConfig pc = new PackageConfig();// Package configuration
  • (package_name);
  • (pc);
  • }
  • private static void setDataSource() {
  • DataSourceConfig dsc = new DataSourceConfig();
  • (url);
  • (driverName);
  • (userName);
  • (password);
  • (dsc);
  • }
  • }