懒羊羊
2023-08-30 1ac2bc1590406d9babec036e154d8d08f34a6aa1
提交 | 用户 | 时间
1ac2bc 1 package cn.stylefeng.guns.gen.core.generator.guns;
2
3 import cn.stylefeng.guns.gen.core.generator.base.model.ContextParam;
4 import cn.stylefeng.guns.gen.core.generator.guns.controller.GunsControllerGenerator;
5 import cn.stylefeng.guns.gen.core.generator.guns.html.GunsPageAddGenerator;
6 import cn.stylefeng.guns.gen.core.generator.guns.html.GunsPageEditGenerator;
7 import cn.stylefeng.guns.gen.core.generator.guns.html.GunsPageIndexGenerator;
8 import cn.stylefeng.guns.gen.core.generator.guns.js.GunsPageAddJsGenerator;
9 import cn.stylefeng.guns.gen.core.generator.guns.js.GunsPageEditJsGenerator;
10 import cn.stylefeng.guns.gen.core.generator.guns.js.GunsPageIndexJsGenerator;
11 import cn.stylefeng.guns.gen.core.generator.guns.mybatisplus.GunsMpGenerator;
12 import cn.stylefeng.guns.gen.core.generator.guns.sqls.GunsMenuSqlGenerator;
13 import cn.stylefeng.guns.gen.core.generator.restful.mybatisplus.param.MpParam;
14 import com.baomidou.mybatisplus.generator.config.po.TableInfo;
15
16 import java.util.List;
17 import java.util.Map;
18
19 /**
20  * 测试的执行器
21  *
22  * @author fengshuonan
23  * @date 2018-12-18-6:39 PM
24  */
25 public class GunsExecutor {
26
27     /**
28      * 默认的生成器
29      *
30      * @author fengshuonan
31      * @Date 2019/1/13 22:18
32      */
33     public static void executor(ContextParam contextParam, MpParam mpContext) {
34
35         //执行mp的代码生成,生成entity,dao,service,model,生成后保留数据库元数据
36         GunsMpGenerator gunsMpGenerator = new GunsMpGenerator(mpContext);
37         gunsMpGenerator.initContext(contextParam);
38         gunsMpGenerator.doGeneration();
39
40         //获取元数据
41         List<TableInfo> tableInfos = gunsMpGenerator.getTableInfos();
42         Map<String, Map<String, Object>> everyTableContexts = gunsMpGenerator.getEveryTableContexts();
43
44         //遍历所有表
45         for (TableInfo tableInfo : tableInfos) {
46             Map<String, Object> map = everyTableContexts.get(tableInfo.getName());
47
48             //生成控制器
49             GunsControllerGenerator gunsControllerGenerator = new GunsControllerGenerator(map);
50             gunsControllerGenerator.initContext(contextParam);
51             gunsControllerGenerator.doGeneration();
52
53             //生成主页面html
54             GunsPageIndexGenerator gunsPageIndexGenerator = new GunsPageIndexGenerator(map);
55             gunsPageIndexGenerator.initContext(contextParam);
56             gunsPageIndexGenerator.doGeneration();
57
58             //生成主页面js
59             GunsPageIndexJsGenerator gunsPageIndexJsGenerator = new GunsPageIndexJsGenerator(map);
60             gunsPageIndexJsGenerator.initContext(contextParam);
61             gunsPageIndexJsGenerator.doGeneration();
62
63             //生成添加页面html
64             GunsPageAddGenerator gunsPageAddGenerator = new GunsPageAddGenerator(map);
65             gunsPageAddGenerator.initContext(contextParam);
66             gunsPageAddGenerator.doGeneration();
67
68             //生成添加页面的js
69             GunsPageAddJsGenerator gunsPageAddJsGenerator = new GunsPageAddJsGenerator(map);
70             gunsPageAddJsGenerator.initContext(contextParam);
71             gunsPageAddJsGenerator.doGeneration();
72
73             //生成编辑页面html
74             GunsPageEditGenerator gunsPageEditGenerator = new GunsPageEditGenerator(map);
75             gunsPageEditGenerator.initContext(contextParam);
76             gunsPageEditGenerator.doGeneration();
77
78             //生成编辑页面的js
79             GunsPageEditJsGenerator gunsPageEditJsGenerator = new GunsPageEditJsGenerator(map);
80             gunsPageEditJsGenerator.initContext(contextParam);
81             gunsPageEditJsGenerator.doGeneration();
82
83             //生成菜单的sql
84             GunsMenuSqlGenerator gunsMenuSqlGenerator = new GunsMenuSqlGenerator(map);
85             gunsMenuSqlGenerator.initContext(contextParam);
86             gunsMenuSqlGenerator.doGeneration();
87         }
88     }
89
90     public static void main(String[] args) {
91
92         ContextParam contextParam = new ContextParam();
93
94         contextParam.setJdbcDriver("com.mysql.jdbc.Driver");
95         contextParam.setJdbcUserName("root");
96         contextParam.setJdbcPassword("root");
97         contextParam.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/generator_platform?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=CTT");
98         contextParam.setOutputPath("temp");
99         contextParam.setAuthor("fengshuonan");
100         contextParam.setProPackage("cn.stylefeng.guns.modular.test");
101
102         MpParam mpContextParam = new MpParam();
103         mpContextParam.setGeneratorInterface(true);
104         mpContextParam.setIncludeTables(new String[]{"test"});
105         mpContextParam.setRemoveTablePrefix(new String[]{"sys_"});
106
107         GunsExecutor.executor(contextParam, mpContextParam);
108     }
109
110 }