一对多的代码生成器使用示例:
//第一步:设置主表
CodeParamEntity codeParamEntityIn = new CodeParamEntity(); codeParamEntityIn.setTableName("jeecg_order_main");//主表[表名] codeParamEntityIn.setEntityName("Demo4ManyKey"); //主表[实体名] codeParamEntityIn.setEntityPackage("jeecg"); //主表[包名] codeParamEntityIn.setFtlDescription("订单主数据"); //主表[描述]
//第二步:设置子表集合
List<SubTableEntity> subTabParamIn = new ArrayList<SubTableEntity>();
//[1].子表一
SubTableEntity po = new SubTableEntity();
po.setTableName("jeecg_order_custom"); //子表[表名] po.setEntityName("DemoMany4CustomKey"); //子表[实体名] po.setEntityPackage("jeecg"); //子表[包]
po.setFtlDescription("订单客户明细");//子表[描述]
po.setForeignKeys(new String[]{"GORDER_OBID","GO_ORDER_CODE"});//子表[外键:与主表关 联外键]
subTabParamIn.add(po);
//[2].子表二
SubTableEntity po2 = new SubTableEntity(); po2.setTableName("jeecg_order_product"); //子表[表名] po2.setEntityName("DemoMany4ProductKey"); // 子表[实体名] po2.setEntityPackage("jeecg"); //子表[包]
po2.setFtlDescription("订单产品明细"); //子表[描述]
po2.setForeignKeys(new String[]{"GORDER_OBID","GO_ORDER_CODE"});//子表[外键:与主表 关联外键]
subTabParamIn.add(po2);
codeParamEntityIn.setSubTabParam(subTabParamIn);
//第三步:一对多(父子表)数据模型,代码生成 CodeGenerateOneToMany.oneToManyCreate(subTabParamIn, codeParamEntityIn);
使用规范
1. 目前代码生成器默认的主键生成策略为 UUID
2. 主表和子表的目录最好保持一致
3. 子表和主表的外键规则如下:
a) 主表和子表的外键字段名字,必须相同(除主键 ID 外)
b) 子表引用主表主键 ID 作为外键,外键字段必须以_ID 结尾
更多推荐
jeecg平台 一对多代码生成器使用
发布评论