(三)多表代码生成

1、

2、java代码

 1 package org.jeecg;
 2 
 3 import java.util.ArrayList;
 4 import java.util.List;
 5 
 6 import org.jeecgframework.codegenerate.generate.impl.CodeGenerateOneToMany;
 7 import org.jeecgframework.codegenerate.generate.pojo.onetomany.MainTableVo;
 8 import org.jeecgframework.codegenerate.generate.pojo.onetomany.SubTableVo;
 9 
10  */
11 public class JeecgOneToMainUtil {
12 
13     /**
14      * 一对多(父子表)数据模型,生成方法
15      * @param args
16      */
17     public static void main(String[] args) {
18         //第一步:设置主表配置
19         MainTableVo mainTable = new MainTableVo();
20         mainTable.setTableName("jeecg_order_main");//表名
21         mainTable.setEntityName("TestOrderMain");     //实体名
22         mainTable.setEntityPackage("test2");     //包名
23         mainTable.setFtlDescription("订单");     //描述
24         
25         //第二步:设置子表集合配置
26         List<SubTableVo> subTables = new ArrayList<SubTableVo>();
27         //[1].子表一
28         SubTableVo po = new SubTableVo();
29         po.setTableName("jeecg_order_customer");//表名
30         po.setEntityName("TestOrderCustom");        //实体名
31         po.setEntityPackage("test2");            //包名
32         po.setFtlDescription("客户明细");       //描述
33         //子表外键参数配置
34         /*说明: 
35          * a) 子表引用主表主键ID作为外键,外键字段必须以_ID结尾;
36          * b) 主表和子表的外键字段名字,必须相同(除主键ID外);
37          * c) 多个外键字段,采用逗号分隔;
38         */
39         po.setForeignKeys(new String[]{"order_id"});
40         subTables.add(po);
41         //[2].子表二
42         SubTableVo po2 = new SubTableVo();
43         po2.setTableName("jeecg_order_ticket");        //表名
44         po2.setEntityName("TestOrderTicket");            //实体名
45         po2.setEntityPackage("test2");                 //包名
46         po2.setFtlDescription("产品明细");            //描述
47         //子表外键参数配置
48         /*说明: 
49          * a) 子表引用主表主键ID作为外键,外键字段必须以_ID结尾;
50          * b) 主表和子表的外键字段名字,必须相同(除主键ID外);
51          * c) 多个外键字段,采用逗号分隔;
52         */
53         po2.setForeignKeys(new String[]{"order_id"});
54         subTables.add(po2);
55         mainTable.setSubTables(subTables);
56         
57         //第三步:一对多(父子表)数据模型,代码生成
58         try {
59             new CodeGenerateOneToMany(mainTable,subTables).generateCodeFile();
60 
61             /**
62              *  可以指定路径 跟模板
63              *    项目路径默认使用jeecg_config.propertise 中的路径
64              *  模板路径默认使用onetomany:/jeecg/code-template/onetomany 
65              */
66             //new CodeGenerateOneToMany(mainTable,subTables).generateCodeFile(projectPath,templatePath);
67         } catch (Exception e) {
68             e.printStackTrace();
69         }
70     }
71 }
多表代码生成

 3、生成代码目录结构()

 

4、导入前端查看

    主表

    子表

 

posted @ 2019-07-24 14:54  千彧  阅读(707)  评论(1编辑  收藏  举报