添加依赖

    1. <!---代码生成器模块-->
    2. <dependency>
    3. <groupId>xyz.erupt</groupId>
    4. <artifactId>erupt-generator</artifactId>
    5. <version>1.8.5</version>
    6. </dependency>

    导入成功以后重新启动项目,即可看到后台代码生成的相关菜单

    image.png

    不妨来使用代码生成器来创建一个实体类和对应的数据表

    对应的填好我们的配置信息
    image.png

    查看自动生成代码
    image.png
    image.png

    去项目中创建 enity.Group 实体类,把生成代码复制粘贴进去,对主键id部分的代码进行一定的修改后

    修改后的代码示例

    1. package com.example.demo2.springbootmybatis.entiy;
    2. /*
    3. * Copyright © 2020-2035 erupt.xyz All rights reserved.
    4. * Author: YuePeng (erupts@126.com)
    5. */
    6. import javax.persistence.*;
    7. import xyz.erupt.annotation.*;
    8. import xyz.erupt.annotation.sub_erupt.*;
    9. import xyz.erupt.annotation.sub_field.*;
    10. import xyz.erupt.annotation.sub_field.sub_edit.*;
    11. import xyz.erupt.upms.model.base.HyperModel;
    12. import xyz.erupt.jpa.model.BaseModel;
    13. import java.util.Set;
    14. import java.util.Date;
    15. @Erupt(name = "小组")
    16. @Table(name = "t_group")
    17. @Entity
    18. public class Group{
    19. @EruptField(
    20. views = @View(
    21. title = "编号", sortable = true
    22. ),
    23. edit = @Edit(
    24. title = "编号",
    25. type = EditType.NUMBER, search = @Search, notNull = true,
    26. numberType = @NumberType
    27. )
    28. )
    29. @Id
    30. private Integer id;
    31. @EruptField(
    32. views = @View(
    33. title = "小组名称"
    34. ),
    35. edit = @Edit(
    36. title = "小组名称",
    37. type = EditType.INPUT, search = @Search, notNull = true,
    38. inputType = @InputType
    39. )
    40. )
    41. private String name;
    42. @EruptField(
    43. views = @View(
    44. title = "小组简介"
    45. ),
    46. edit = @Edit(
    47. title = "小组简介",
    48. type = EditType.TEXTAREA, search = @Search, notNull = true
    49. )
    50. )
    51. private @Lob String intro;
    52. @EruptField(
    53. views = @View(
    54. title = "组员"
    55. ),
    56. edit = @Edit(
    57. title = "组员",
    58. type = EditType.TAB_TABLE_REFER, search = @Search, notNull = true
    59. )
    60. )
    61. @ManyToMany
    62. @JoinTable(name = "group_admin",
    63. joinColumns = @JoinColumn(name = "group_id", referencedColumnName = "id"),
    64. inverseJoinColumns = @JoinColumn(name = "admin_id", referencedColumnName = "id"))
    65. private Set<Admin> teamer;
    66. @EruptField(
    67. views = @View(
    68. title = "组长",
    69. column = "name"
    70. ),
    71. edit = @Edit(
    72. title = "组长",
    73. type = EditType.REFERENCE_TABLE, search = @Search, notNull = true,
    74. referenceTableType = @ReferenceTableType(id = "id", label = "name")
    75. )
    76. )
    77. @ManyToOne
    78. private Admin leader;
    79. }

    重新启动项目,让jpa帮我们去生成对应的数据表

    image.png

    配置我们的后台菜单
    image.png

    填写创建小组的信息,创建一个新的小组
    image.png

    两个小组就成功创建成功了
    我们并没有写一点CURD的代码!!!
    image.png

    能看到我们包含的组员有哪些
    image.png