添加依赖
<!---代码生成器模块-->
<dependency>
<groupId>xyz.erupt</groupId>
<artifactId>erupt-generator</artifactId>
<version>1.8.5</version>
</dependency>
导入成功以后重新启动项目,即可看到后台代码生成的相关菜单
不妨来使用代码生成器来创建一个实体类和对应的数据表
对应的填好我们的配置信息
查看自动生成代码
去项目中创建 enity.Group 实体类,把生成代码复制粘贴进去,对主键id部分的代码进行一定的修改后
修改后的代码示例
package com.example.demo2.springbootmybatis.entiy;
/*
* Copyright © 2020-2035 erupt.xyz All rights reserved.
* Author: YuePeng (erupts@126.com)
*/
import javax.persistence.*;
import xyz.erupt.annotation.*;
import xyz.erupt.annotation.sub_erupt.*;
import xyz.erupt.annotation.sub_field.*;
import xyz.erupt.annotation.sub_field.sub_edit.*;
import xyz.erupt.upms.model.base.HyperModel;
import xyz.erupt.jpa.model.BaseModel;
import java.util.Set;
import java.util.Date;
@Erupt(name = "小组")
@Table(name = "t_group")
@Entity
public class Group{
@EruptField(
views = @View(
title = "编号", sortable = true
),
edit = @Edit(
title = "编号",
type = EditType.NUMBER, search = @Search, notNull = true,
numberType = @NumberType
)
)
@Id
private Integer id;
@EruptField(
views = @View(
title = "小组名称"
),
edit = @Edit(
title = "小组名称",
type = EditType.INPUT, search = @Search, notNull = true,
inputType = @InputType
)
)
private String name;
@EruptField(
views = @View(
title = "小组简介"
),
edit = @Edit(
title = "小组简介",
type = EditType.TEXTAREA, search = @Search, notNull = true
)
)
private @Lob String intro;
@EruptField(
views = @View(
title = "组员"
),
edit = @Edit(
title = "组员",
type = EditType.TAB_TABLE_REFER, search = @Search, notNull = true
)
)
@ManyToMany
@JoinTable(name = "group_admin",
joinColumns = @JoinColumn(name = "group_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "admin_id", referencedColumnName = "id"))
private Set<Admin> teamer;
@EruptField(
views = @View(
title = "组长",
column = "name"
),
edit = @Edit(
title = "组长",
type = EditType.REFERENCE_TABLE, search = @Search, notNull = true,
referenceTableType = @ReferenceTableType(id = "id", label = "name")
)
)
@ManyToOne
private Admin leader;
}
重新启动项目,让jpa帮我们去生成对应的数据表
配置我们的后台菜单
填写创建小组的信息,创建一个新的小组
两个小组就成功创建成功了
我们并没有写一点CURD的代码!!!
能看到我们包含的组员有哪些