搭建低代码平台plus代码生成器的集成

搭建低代码平台plus代码生成器的集成

mybatis-plus提供了代码自动生成器;使用代码生成器可以根据数据库表结构生成我们需要的代码结构,节省了我们建各种类的时间。

以下是集成mybatis-plus代码生成器的具体配置:

pom.xml

com.baomidou mybatis-plus-generator ${mybatis-plus.version} compile

代码生成器工具类

public class CodeGeneration { public static String scanner (String tip){ Scanner scanner = new Scanner(System.in); StringBuilder help = new StringBuilder(); help.append(“请输入” + tip + “:”); System.out.println(help.toString()); if (scanner.hasNext()) { String ipt = scanner.next(); /*if (StringUtils.isNotEmpty(ipt)) { return ipt; }*/ if (ipt.length()>0) { return ipt; } } throw new MybatisPlusException(“请输入正确的” + tip + “!”); } public static void main (String[]args){ // 代码生成器 AutoGenerator mpg = new AutoGenerator(); // 全局配置 GlobalConfig gc = new GlobalConfig(); String projectPath = “D:/JAVA/crmvideo/src/main/java”; gc.setOutputDir(projectPath); gc.setAuthor(“wlx”); gc.setOpen(false); mpg.setGlobalConfig(gc); // 数据源配置 DataSourceConfig dsc = new DataSourceConfig(); dsc.setUrl(“jdbc:mysql://127.0.0.1:3306/crmvideo?characterEncoding=utf8&serverTimezone=UTC”); dsc.setDriverName(“com.mysql.jdbc.Driver”); dsc.setUsername(“root”); dsc.setPassword(“123456”); mpg.setDataSource(dsc); // 包配置 PackageConfig pc = new PackageConfig(); pc.setModuleName(scanner(“模块名”)); pc.setParent(“com.wangkai”); pc.setController(“controller”); pc.setService(“service”); pc.setServiceImpl(“serviceImpl”); pc.setMapper(“mapper”); pc.setEntity(“entity”); pc.setXml(“xml”); mpg.setPackageInfo(pc); // 自定义配置 InjectionConfig cfg = new InjectionConfig() { @Override public void initMap() { // to do nothing } }; // 如果模板引擎是 freemarker String templatePath = “/templates/mapper.xml.ftl”; // 自定义输出配置 List focList = new ArrayList(); // 自定义配置会被优先输出 focList.add(new FileOutConfig(templatePath) { @Override public String outputFile(TableInfo tableInfo) { return projectPath + “/com/wangkai/” + pc.getModuleName() + “/xml/” +tableInfo.getEntityName() + “Mapper” + StringPool.DOT_XML; } }); cfg.setFileOutConfigList(focList); mpg.setCfg(cfg); // 配置模板 TemplateConfig templateConfig = new TemplateConfig(); // 配置自定义输出模板 //指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别 // templateConfig.setEntity(“templates/entity2.java”); // 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.setEntityLombokModel(true); strategy.setRestControllerStyle(true); strategy.setSuperEntityColumns(“id”); strategy.setInclude(scanner(“表名,多个英文逗号分割”).split(“,”)); strategy.setControllerMappingHyphenStyle(true); strategy.setTablePrefix(pc.getModuleName() + “_”); mpg.setStrategy(strategy); mpg.setTemplateEngine(new FreemarkerTemplateEngine()); mpg.execute(); }}

代码生成器生成的代码结构

代码生成器生成的代码结构

郑重声明:本文内容及图片均整理自互联网,不代表本站立场,版权归原作者所有,如有侵权请联系管理员(admin#wlmqw.com)删除。
上一篇 2022年7月21日 09:45
下一篇 2022年7月21日 09:45

相关推荐

联系我们

联系邮箱:admin#wlmqw.com
工作时间:周一至周五,10:30-18:30,节假日休息