mybatisplus版本的⽣成器,⽣成实体类,mapper,rvice,controller mybatisplus版本的⽣成器,⽣成实体类,mapper,rvice,controller
包名路径控制台⾃定义,⾃带swagger注解,继承类⾃定义
package com.zdy;
import batisplus.annotation.DbType;
import ator.AutoGenerator;
import ator.InjectionConfig;
import fig.*;
import fig.po.TableInfo;
import fig.rules.NamingStrategy;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
president
import java.io.File;
import java.io.IOException;
import java.util.*;
/**
* @author yn
* USER 表⽰主机名
* @date
* DATA 为⽂档创建⽇期,TIME 为详细创建时间
* 演⽰例⼦,执⾏ main ⽅法控制台输⼊模块表名回车⾃动⽣成对应项⽬⽬录中
*/
@Component
public class CodeGenerator {
/**
* 项⽬路径
*
*/
private static String canonicalPath ="";
/**
* 基本包名
*/
private static String baPackage ="com.zdy.";
/**
* 作者
*/
dvd rprivate static String authorName ="yinna";
private static String[] tables ={"fsr_option"};
亲爱的用英文怎么说/**
* table前缀
*/
private static String[] prefix ={"fsr_"};
/**
* 数据库类型
*/
private static DbType dbType = DbType.MYSQL;
坂田英语培训/**
* 数据库配置四要素
*/
private static String driverName ="net.sf.log4jdbc.sql.jdbcapi.DriverSpy";
private static String url ="jdbc:log4jdbc:mysql://192.168.10.241:3306/psycloudpro?rverTimezone=Asia/Shanghai&characterEncoding=utf8&uSSL=fa l";
private static String urname ="good";
private static String password ="good";
public static void main(String[] args){
// 代码⽣成器
AutoGenerator mpg =new AutoGenerator();
Scanner scan =new Scanner(System.in);
/**
* 获取项⽬路径
*/
try{
canonicalPath =new File("").getCanonicalPath();
}catch(IOException e){
e.printStackTrace();
showergel}
// 全局配置
GlobalConfig globalConfig =new GlobalConfig();
globalConfig.tOutputDir(canonicalPath +"/zdy-application/zdy-start/src/main/java"); globalConfig.tFileOverride(true);
globalConfig.tActiveRecord(true);
globalConfig.tEnableCache(fal);
globalConfig.tBaResultMap(true);
globalConfig.tBaColumnList(true);
globalConfig.tSwagger2(true);
globalConfig.tOpen(fal);
globalConfig.tAuthor(authorName);
globalConfig.tMapperName("%sMapper");
globalConfig.tXmlName("%sMapper");留学语言
globalConfig.tServiceName("%sService");
globalConfig.tServiceImplName("%sServiceImpl");
英语春节作文
globalConfig.tControllerName("%sController");
mpg.tGlobalConfig(globalConfig);
// 数据源配置
DataSourceConfig dataSourceConfig =new DataSourceConfig();
dataSourceConfig.tDriverName(driverName);
dataSourceConfig.tDbType(dbType);
dataSourceConfig.tUrl(url);
dataSourceConfig.tUrname(urname);
dataSourceConfig.tPassword(password);
mpg.tDataSource(dataSourceConfig);
道歉的英文/
/ 包配置
PackageConfig packageConfig =new PackageConfig();
System.out.println("请输⼊包名");
String next = ();
packageConfig.tParent(baPackage+next);
packageConfig.tController("controller");
packageConfig.tEntity("ity");
packageConfig.tMapper("mapper");
packageConfig.tService("rvice");
packageConfig.tServiceImpl("rvice.impl");
mpg.tPackageInfo(packageConfig);
/
/ ⾃定义配置
InjectionConfig cfg =new InjectionConfig(){
@Override
public void initMap(){
// to do nothing
}
};
/**
* 注⼊⾃定义配置
*/
// 注⼊⾃定义配置,可以在 VM 中使⽤ cfg.abc 设置的值
InjectionConfig abc =new InjectionConfig(){
@Override
public void initMap(){
Map<String, Object> map =new HashMap<String, Object>();
map.put("abc",Config().getGlobalConfig().getAuthor()+"-mp");
this.tMap(map);
}
};
//⾃定义⽂件输出位置(⾮必须)
List<FileOutConfig> fileOutList =new ArrayList<FileOutConfig>();
vfileOutList.add(new FileOutConfig("/l.vm"){
@Override
public String outputFile(TableInfo tableInfo){
return canonicalPath +"/zdy-application/zdy-start/src/main/resources/mapper/"+ next +"/"+ EntityName()+"l";
}
});
abc.tFileOutConfigList(fileOutList);
mpg.tCfg(abc);
// 配置模板
TemplateConfig templateConfig =new TemplateConfig();
templateConfig.tXml(null);
mpg.tTemplate(templateConfig);
// 策略配置
StrategyConfig strategyConfig =new StrategyConfig();
strategyConfig.tSuperServiceClass("sion.rvice.IService");
strategyConfig.tSuperServiceImplClass("sion.rvice.impl.ServiceImpl");
strategyConfig.tSuperEntityClass("com.del.ba.BaEntity");
strategyConfig.tSuperMapperClass("apper.BaMapper");
strategyConfig.tSuperEntityColumns("del_flag","crt_ur_id","crt_ur_name","remark","crt_time","upd_ur_id","upd_ur_name","upd_time","ri alVersionUID");
System.out.println("请输⼊表名,多个以英⽂,隔开");
//表
language exchangestrategyConfig.().split(","));
System.out.println("请输⼊前缀");
//前缀
strategyConfig.());
strategyConfig.tEntityBuilderModel(true);
strategyConfig.tRestControllerStyle(true);
strategyConfig.tNaming(NamingStrategy.underline_to_camel);
//开启lombok注解
strategyConfig.tEntityLombokModel(true);
mpg.tStrategy(strategyConfig);
}
}