//package com.monkeylessey.gen.utils;
|
//
|
//import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
//import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
//import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
|
//import com.baomidou.mybatisplus.generator.config.OutputFile;
|
//import com.baomidou.mybatisplus.generator.config.TemplateConfig;
|
//import com.monkeylessey.sys.domain.base.AbsEntity;
|
//import com.monkeylessey.gen.enums.GenFileTypeEnum;
|
//import com.monkeylessey.gen.gen.MyVelocityTemplateEngine;
|
//import org.apache.commons.lang3.StringUtils;
|
//
|
//import java.util.*;
|
//import java.util.function.Consumer;
|
//
|
///**
|
// * 该类用于后端人员直接使用
|
// *
|
// * @author 29443
|
// * @date 2022/4/7
|
// */
|
//public class GenUtil {
|
//
|
// public static void main(String[] args) {
|
// // 要生成代码的表
|
// List<String> tableNames = Arrays.asList(
|
// "sys_role"
|
// );
|
// // 为哪个模块生成代码
|
// String forWhichModule = "gen-demo";
|
// plusGener(tableNames, forWhichModule);
|
// }
|
//
|
// /**
|
// * 代码生成方法
|
// *
|
// * @param genTables 要生成代码的表
|
// * @param forWhichModule 为哪个模块生成代码
|
// */
|
// public static void plusGener(List<String> genTables, String forWhichModule) {
|
// String outDir = "";
|
// String mapperDir = "";
|
// if (StringUtils.isNotBlank(forWhichModule)) {
|
// // 多模块应用
|
// outDir = System.getProperty("user.dir") + "\\" + forWhichModule + "\\src\\main\\java";
|
// mapperDir = System.getProperty("user.dir") + "\\" + forWhichModule + "\\src\\main\\resources\\mapper";
|
// } else {
|
// // 单模块应用
|
// outDir = System.getProperty("user.dir") + "\\src\\main\\java";
|
// mapperDir = System.getProperty("user.dir") + "\\src\\main\\resources\\mapper";
|
// }
|
// System.out.println(System.getProperty("user.dir"));
|
// String finalOutDir = outDir;
|
// String finalMapperDir = mapperDir;
|
//
|
// // 自定义的模板路径
|
// Map<String, String> customFileMap = new HashMap();
|
// customFileMap.put(GenFileTypeEnum.FORM.getValue(), "/templates/form.java.vm");
|
// customFileMap.put(GenFileTypeEnum.VO.getValue(), "/templates/vo.java.vm");
|
// customFileMap.put(GenFileTypeEnum.QUERY.getValue(), "/templates/query.java.vm");
|
// customFileMap.put(GenFileTypeEnum.VIEW.getValue(), "/templates/vueView.vue.vm");
|
// customFileMap.put(GenFileTypeEnum.DIALOG.getValue(), "/templates/vueDialog.vue.vm");
|
// customFileMap.put(GenFileTypeEnum.TABLE.getValue(), "/templates/vueTable.vue.vm");
|
// customFileMap.put(GenFileTypeEnum.STORE.getValue(), "/templates/vueStore.js.vm");
|
// customFileMap.put(GenFileTypeEnum.API.getValue(), "/templates/vueApi.js.vm");
|
//
|
// // 自定义数据
|
// Map<String, Object> customDataMap = new HashMap();
|
// // 数据校验分组
|
// customDataMap.put("addGroup", "com.monkeylessey.group.AddGroup");
|
// customDataMap.put("updateGroup", "com.monkeylessey.group.UpdateGroup");
|
// // 统一响应类
|
// customDataMap.put("responseDataName", "Result");
|
// customDataMap.put("responseDataPath", "com.monkeylessey.response.Result");
|
//// // 是否存在创建者字段
|
//// customDataMap.put("hasCreateBy", true);
|
//// // 是否存在修改者字段
|
//// customDataMap.put("hasUpdateBy", true);
|
//// // 是否是父子嵌套表
|
//// customDataMap.put("isNest", true);
|
// // 指向父的字段
|
//// customDataMap.put("parentPoint", "ParentId");
|
//// // 分页类名
|
//// customDataMap.put("pageClassName", "PageData");
|
//// // 分页类所在路径
|
//// customDataMap.put("pagePath", "com.monkeylessey.sys.domain");
|
//
|
// FastAutoGenerator.create("jdbc:mysql://39.108.83.106:3306/start", "root", "Xp@199866")
|
// .globalConfig(builder -> {
|
// builder.author("向培") //作者
|
// .outputDir(finalOutDir) //输出路径(写到java目录)
|
// .enableSwagger() //开启swagger
|
// .commentDate("yyyy-MM-dd");
|
// //.fileOverride(); //开启覆盖之前生成的文件
|
//
|
// })
|
// .packageConfig(builder -> {
|
// builder.parent("com.monkeylessey")
|
// //.moduleName("onceCode")
|
// .entity("domain.entity")
|
// .service("service")
|
// .serviceImpl("service.impl")
|
// .controller("controller")
|
// .mapper("mapper")
|
// .other("domain")
|
// .xml("mapper")
|
// .pathInfo(Collections.singletonMap(OutputFile.other, finalOutDir + "\\domain"))
|
// .pathInfo(Collections.singletonMap(OutputFile.xml, finalMapperDir));
|
// })
|
// .strategyConfig(builder -> {
|
// builder.addInclude(genTables)
|
// //.addTablePrefix("sys_")
|
// .serviceBuilder()
|
// .formatServiceFileName("%sService")
|
// .formatServiceImplFileName("%sServiceImpl")
|
// .entityBuilder()
|
// // 需要说明的是,父类是需要自己创建的,下面的父类字段也是你自己创建才行。plus不会说发现父类并没有id而创建id字段
|
// .superClass(AbsEntity.class)
|
// // 指定哪些字段在父表中,实体类将不会生成这些字段了
|
// .addSuperEntityColumns("id", "gmt_create", "gmt_update", "deleted")
|
// .enableLombok()
|
// // 开启链式调用
|
// .enableChainModel()
|
// //.logicDeleteColumnName("deleted")
|
// .enableTableFieldAnnotation()
|
// .controllerBuilder()
|
// // 映射路径使用连字符格式,而不是驼峰
|
// .enableHyphenStyle()
|
// .formatFileName("%sController")
|
// .enableRestStyle()
|
// .mapperBuilder()
|
// //生成通用的resultMap
|
// .enableBaseResultMap()
|
// .superClass(BaseMapper.class)
|
// .formatMapperFileName("%sMapper")
|
// .enableMapperAnnotation()
|
// .formatXmlFileName("%sMapper");
|
// })
|
// .injectionConfig(builder -> {
|
// builder.customMap(customDataMap)
|
// .customFile(customFileMap);
|
// })
|
// .templateConfig(new Consumer<TemplateConfig.Builder>() {
|
// // 使用自定义entity模板
|
// @Override
|
// public void accept(TemplateConfig.Builder builder) {
|
// builder.entity("templates/entity.java");
|
// }
|
// })
|
// // 默认的是Velocity引擎模板
|
// .templateEngine(new MyVelocityTemplateEngine())
|
// .execute();
|
// }
|
//}
|