不飞则已,一飞冲天;不鸣则已,一鸣惊人。这篇文章主要讲述鑷姩鐢熸垚entry-mapper-service-controller相关的知识,希望能为你提供帮助。
【鑷姩鐢熸垚entry-mapper-service-controller】鏍囩锛?a href='http://www.mamicode.com/so/1/engine' title='engine'>engine
config
tty
list
void
rac
gpo
api
exec
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.DbColumnType;
import com.baomidou.mybatisplus.generator.config.rules.IColumnType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class CodeGenerator {
private static String table = "sys_apiuser";
public static void main(String[] args) {
// 浠g爜鐢熸垚鍣?br />AutoGenerator mpg = new AutoGenerator();
// 鍏ㄥ眬閰嶇疆
GlobalConfig gc = new GlobalConfig();
String projectPath = "D:\svnProject\ShenZhenPlatform";
gc.setOutputDir(projectPath + "/src/main/java");
gc.setAuthor("jack");
gc.setOpen(false);
gc.setBaseResultMap(true);
mpg.setGlobalConfig(gc);
// 鏁版嵁婧愰厤缃?br />DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://192.168.9.102:3306/parkcloud_sz?characterEncoding=utf8& zeroDateTimeBehavior=convertToNull& userSSL=false");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("123456");
mpg.setDataSource(dsc);
dsc.setTypeConvert(new ITypeConvert() {
@Override
public IColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType) {
String t = fieldType.toLowerCase();
if (t.contains("char")) {
return DbColumnType.STRING;
} else if (t.contains("bigint")) {
return DbColumnType.LONG;
} else if (t.contains("int")) {
return DbColumnType.INTEGER;
} else if (!t.contains("date") & & !t.contains("time") & & !t.contains("year")) {
if (t.contains("text")) {
return DbColumnType.STRING;
} else if (t.contains("bit")) {
return DbColumnType.BOOLEAN;
} else if (t.contains("decimal")) {
return DbColumnType.BIG_DECIMAL;
} else if (t.contains("clob")) {
return DbColumnType.CLOB;
} else if (t.contains("blob")) {
return DbColumnType.BYTE_ARRAY;
} else if (t.contains("float")) {
return DbColumnType.FLOAT;
} else if (t.contains("real")) {
return DbColumnType.FLOAT;
} else if (t.contains("double")) {
return DbColumnType.DOUBLE;
} else if (!t.contains("json") & & !t.contains("enum")) {
return t.contains("boolean") ? DbColumnType.BOOLEAN : DbColumnType.STRING;
} else {
return DbColumnType.STRING;
}
} else {
return DbColumnType.DATE;
}
}
});
// 鍖呴厤缃?br />/*PackageConfig pc = new PackageConfig();
pc.setModuleName(scanner("妯″潡鍚?));
pc.setParent("cn.com.fitalent");
mpg.setPackageInfo(pc); */
//鍖呭悕绛栫暐閰嶇疆
PackageConfig pc = new PackageConfig();
// pc.setModuleName(scanner("妯″潡鍚?));
pc.setParent("com.yicheplatform.shenzhen");
mpg.setPackageInfo(pc);
// 鑷畾涔夐厤缃?br />InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
// to do nothing
}
};
// 濡傛灉妯℃澘寮曟搸鏄?freemarker
//String templatePath = "/templates/mapper.xml.ftl";
// 濡傛灉妯℃澘寮曟搸鏄?velocity
String templatePath = "/templates/mapper.xml.vm";
// 鑷畾涔夎緭鍑洪厤缃?br />List< FileOutConfig> focList = new ArrayList< > ();
// 鑷畾涔夐厤缃細琚紭鍏堣緭鍑?br />focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
// 鑷畾涔夎緭鍑烘枃浠跺悕
return projectPath + "/src/main/resources/mapper/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
// 閰嶇疆妯℃澘
TemplateConfig templateConfig = new TemplateConfig();
// 閰嶇疆鑷畾涔夎緭鍑烘ā鏉?br />// templateConfig.setEntity();
// templateConfig.setService();
// templateConfig.setController();
templateConfig.setXml(null);
mpg.setTemplate(templateConfig);
// 绛栫暐閰嶇疆
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
//strategy.setSuperEntityClass("com.yicheplatform.shenzhen.entity.BaseEntity");
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
//strategy.setSuperControllerClass("com.fialent.cms.BaseController");
//String tableStrings = scanner("琛ㄥ悕");
strategy.setInclude(table.split(","));
// strategy.setSuperEntityColumns("id");
// strategy.setSuperEntityColumns("create_time");
strategy.setControllerMappingHyphenStyle(true);
strategy.setTablePrefix(pc.getModuleName() + "_");
mpg.setStrategy(strategy);
// mpg.setTemplateEngine(new FreemarkerTemplateEngine());
mpg.execute();
}
}
推荐阅读
- uni-app平台判断 | uni app判断h5 小程序 app 等不同平台
- 解决Android无法请求网络权限
- kotlin作用域函数(letrunalsoapplywith的区别)
- Spring Boot的特性(SpringApplication流式构建API)
- appium的简单调用以及mumu模拟器的使用
- Kotlin语言打造Android AI语音助手
- Gnirehtetadb安卓手机通过USB连接到电脑上网
- ApplicationContextAware得到ApplicationContext的原理
- .net webapi+autofac+autoMapper 单元测试