JeecgOneToMainUtil.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package org.jeecg;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import org.jeecgframework.codegenerate.generate.impl.CodeGenerateOneToMany;
  5. import org.jeecgframework.codegenerate.generate.pojo.onetomany.MainTableVo;
  6. import org.jeecgframework.codegenerate.generate.pojo.onetomany.SubTableVo;
  7. /**
  8. * 代码生成器入口【一对多】
  9. * @Author 张代浩
  10. * @site www.jeecg.org
  11. *
  12. */
  13. public class JeecgOneToMainUtil {
  14. /**
  15. * 一对多(父子表)数据模型,生成方法
  16. * @param args
  17. */
  18. public static void main(String[] args) {
  19. //第一步:设置主表配置
  20. MainTableVo mainTable = new MainTableVo();
  21. //表名
  22. mainTable.setTableName("ctop_material_info");
  23. //实体名
  24. mainTable.setEntityName("MaterialInfo");
  25. //包名
  26. mainTable.setEntityPackage("ctop");
  27. //描述
  28. mainTable.setFtlDescription("素材库");
  29. //第二步:设置子表集合配置
  30. List<SubTableVo> subTables = new ArrayList<SubTableVo>();
  31. //[1].子表一
  32. SubTableVo po = new SubTableVo();
  33. //表名
  34. po.setTableName("ctop_material_ascription");
  35. //实体名
  36. po.setEntityName("MaterialAscription");
  37. //包名
  38. po.setEntityPackage("ctop");
  39. //描述
  40. po.setFtlDescription("素材归属");
  41. //子表外键参数配置
  42. /*说明:
  43. * a) 子表引用主表主键ID作为外键,外键字段必须以_ID结尾;
  44. * b) 主表和子表的外键字段名字,必须相同(除主键ID外);
  45. * c) 多个外键字段,采用逗号分隔;
  46. */
  47. po.setForeignKeys(new String[]{"material_id"});
  48. subTables.add(po);
  49. mainTable.setSubTables(subTables);
  50. //第三步:一对多(父子表)数据模型,代码生成
  51. try {
  52. new CodeGenerateOneToMany(mainTable,subTables).generateCodeFile();
  53. } catch (Exception e) {
  54. e.printStackTrace();
  55. }
  56. }
  57. }