package com.common;import com.baomidou.mybatisplus.annotation.DbType;import com.baomidou.mybatisplus.core.toolkit.StringPool;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.TableFill;import com.baomidou.mybatisplus.generator.config.po.TableInfo;import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;import java.util.ArrayList;import java.util.List;/*** @ClassName : CodeGenerator 类名* @Description : 描述*/public class CodeGenerator {public static void main(String[] args) throws InterruptedException {AutoGenerator mpg = new AutoGenerator();// String[] tableNameList = {"bi_overall_sales_indicators","bi_sales_revenue","bi_business_income","bi_world_map_data","bi_annual_data","bi_sku_model_number_data",// 需要生成的表(表中需有is_delete字段,默认0为正常,1为删除)String[] tableNameList = {"client_order_package_insurance"};// 作者String author = "eden";// 包路径(如需生成admin 更换为 com.yd.mall)String parent = "com.yd.mall";// String parent = "com.yd.mall.portal";// String parent = "com.yd.outer";// 文件路径 (如需生成admin 更换为 com/yd/mall)String filePath = "com/yd/mall";// String filePath = "com/yd/mall/portal";// String filePath = "com/yd/outer";// 项目文件 (如需生成admin 更换为 /mall-admin)String projectDocuments = "/mall-admin";// String projectDocuments = "/mall-portal";// String projectDocuments = "/mall-outer";// 数据库相关信息String jdbcUrl = "jdbc:mysql://10.0.1.137:3306/aiper?useSSL=false&allowPublicKeyRetrieval=true&rewriteBatchedStatements=true";String jdbcName = "root";String jdbcPwd = "FPYz2ZD^gu!*";// 全局配置GlobalConfig gc = new GlobalConfig();String projectPath = System.getProperty("user.dir");gc.setOutputDir(projectPath + projectDocuments + "/src/main/java");gc.setFileOverride(true);gc.setActiveRecord(true);// XML 二级缓存gc.setEnableCache(false);// XML ResultMapgc.setBaseResultMap(true);// XML columListgc.setBaseColumnList(true);gc.setOpen(false);gc.setSwagger2(true);gc.setAuthor(author);// 自定义文件命名,注意 %s 会自动填充表实体属性!gc.setMapperName("%sMapper");gc.setXmlName("%sMapper");gc.setServiceName("%sService");gc.setServiceImplName("%sServiceImpl");gc.setControllerName("%sController");mpg.setGlobalConfig(gc);// 数据源配置DataSourceConfig dsc = new DataSourceConfig();// 这里以mysql为例dsc.setDbType(DbType.MYSQL);dsc.setDriverName("com.mysql.cj.jdbc.Driver");dsc.setUrl(jdbcUrl);dsc.setUsername(jdbcName);dsc.setPassword(jdbcPwd);mpg.setDataSource(dsc);// 包配置PackageConfig pc = new PackageConfig();pc.setParent(parent).setController("controller").setEntity("domain").setService("service").setServiceImpl("service.impl").setMapper("mapper");mpg.setPackageInfo(pc);// 自定义配置InjectionConfig cfg = new InjectionConfig() {@Overridepublic void initMap() {// to do nothing}};List<FileOutConfig> focList = new ArrayList<>();focList.add(new FileOutConfig("/templates/mapper.xml.vm") {@Overridepublic String outputFile(TableInfo tableInfo) {// 自定义输入文件名称return projectPath + projectDocuments + "/src/main/resources/" + filePath + "/mapper/"+ tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;}});focList.add(new FileOutConfig("/templates/controller.java.vm") {@Overridepublic String outputFile(TableInfo tableInfo) {// 自定义输入文件名称return projectPath + projectDocuments + "/src/main/java/" + filePath + "/controller/"+ tableInfo.getEntityName() + "Controller" + StringPool.DOT_JAVA;}});focList.add(new FileOutConfig("/templates/entity.java.vm") {@Overridepublic String outputFile(TableInfo tableInfo) {// 自定义输入文件名称return projectPath + projectDocuments + "/src/main/java/" + filePath + "/domain/"+ tableInfo.getEntityName() + StringPool.DOT_JAVA;}});focList.add(new FileOutConfig("/templates/vo.java.vm") {@Overridepublic String outputFile(TableInfo tableInfo) {// 自定义输入文件名称return projectPath + projectDocuments + "/src/main/java/" + filePath + "/domain/vo/"+ tableInfo.getEntityName() + "Vo" + StringPool.DOT_JAVA;}});focList.add(new FileOutConfig("/templates/request.java.vm") {@Overridepublic String outputFile(TableInfo tableInfo) {// 自定义输入文件名称return projectPath + projectDocuments + "/src/main/java/" + filePath + "/domain/request/"+ tableInfo.getEntityName() + "Request" + StringPool.DOT_JAVA;}});focList.add(new FileOutConfig("/templates/service.java.vm") {@Overridepublic String outputFile(TableInfo tableInfo) {// 自定义输入文件名称return projectPath + projectDocuments + "/src/main/java/" + filePath + "/service/"+ tableInfo.getEntityName() + "Service" + StringPool.DOT_JAVA;}});focList.add(new FileOutConfig("/templates/serviceImpl.java.vm") {@Overridepublic String outputFile(TableInfo tableInfo) {// 自定义输入文件名称return projectPath + projectDocuments + "/src/main/java/" + filePath + "/service/impl/"+ tableInfo.getEntityName() + "ServiceImpl" + StringPool.DOT_JAVA;}});cfg.setFileOutConfigList(focList);mpg.setCfg(cfg);// // 配置模板TemplateConfig templateConfig = new TemplateConfig();// templateConfig.setXml("/templates/mapper.xml");templateConfig.setXml(null);templateConfig.setController("/templates/controller.java");templateConfig.setEntity("/templates/entity.java");templateConfig.setMapper("/templates/mapper.java");mpg.setTemplate(templateConfig);// 策略配置StrategyConfig strategy = new StrategyConfig();//此处可以修改为您的表前缀strategy.setTablePrefix(new String[]{""});strategy.setTableFillList(new ArrayList<TableFill>());// 表名生成策略strategy.setNaming(NamingStrategy.underline_to_camel);strategy.setInclude(tableNameList);// 排除生成的表//strategy.setExclude(new String[]{"test"});// strategy.setSuperControllerClass("com.dev.mybatisPlus.controller.BaseController");strategy.setEntityLombokModel(true);mpg.setStrategy(strategy);// 执行生成mpg.execute();}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。