Erupt框架-左树右表的创建过程

## 先来看一下效果

### 新建类

### 例如创建的类文件名称为 LocationList

文件内填充以下内容

@Erupt(name = "库位管理",
        linkTree = @LinkTree(field = "category") //左树右表配置
)
@Table(name = "base_inventory_list")
@Entity
public class LocationList extends BaseModel {

    @EruptField(
            views = @View(title = "库位名称"),
            edit = @Edit(title = "库位名称", notNull = true, search = @Search(vague = true)) //模糊查询配置
    )
    private String name;

    @ManyToOne
    @EruptField(
            views = @View(title = "所属分类", column = "name"),
            edit = @Edit(title = "所属分类", type = EditType.REFERENCE_TREE, search = @Search, notNull = true, referenceTreeType = @ReferenceTreeType(pid = "parent.id"))
    )
    private LocationTree category; //GoodsCategory类定义请往下看

    @EruptField(
            views = @View(title = "库位地址"),
            edit = @Edit(title = "库位地址", notNull = true, inputType = @InputType(fullSpan = true), search = @Search(vague = true)) //模糊查询配置
    )
    private String address;

    @Lob //定义数据库类为大文本类型,支持存入更多的数据
    @EruptField(
            views = @View(title = "库位描述", type = ViewType.HTML),
            edit = @Edit(title = "库位描述", type = EditType.HTML_EDITOR) //定义为富文本编辑器
    )
    private String description;

}

 

### 引入依赖 报红位置  alt+enter ,理论上需要引入的包是以下,别引错了

import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.LinkTree;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.ViewType;
import xyz.erupt.annotation.sub_field.sub_edit.*;
import xyz.erupt.jpa.model.BaseModel;

import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

### 再创建另外一个类文件  LocationTree ,填入以下内容

@Entity
@Table(name = "base_location_category")
@Erupt(
        name = "库位分类",
        orderBy = "LocationTree.sort",
        tree = @Tree(id = "id", label = "name", pid = "parent.id")
)
public class LocationTree extends BaseModel {

    @EruptField(
            views = @View(title = "名称"),
            edit = @Edit(title = "名称", notNull = true)
    )
    private String name;

    @EruptField(
            views = @View(title = "显示顺序"),
            edit = @Edit(title = "显示顺序")
    )
    private Integer sort;

    @ManyToOne
    @EruptField(
            edit = @Edit(
                    title = "上级树节点",
                    type = EditType.REFERENCE_TREE,
                    referenceTreeType = @ReferenceTreeType(pid = "parent.id")
            )
    )
    private LocationTree parent;


}

### 启动项目,然后添加菜单 

进入 系统管理--菜单维护

 ### 刷新页面,OK

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Erupt 框架中,可以通过 `@Button` 注解来实现自定义按钮的功能。下面是一个简单的示例,以实现一个“清空数据”按钮为例: 1. 首先,在你要自定义按钮的实体类中,添加一个`@Button`注解,并且指定按钮的名称和图标: ```java @Entity @Table(name = "t_user") @Erupt(name = "用户管理") public class User { // 省略其他字段 @Button("清空数据") @Icon(value = "fa fa-trash", color = Icon.Color.RED) public void clearData() { // 清空数据的具体实现逻辑 } } ``` 2. 在 `EruptConfig` 中,需要添加一个 `EruptButtonModel` 来对按钮进行配置: ```java @Configuration public class EruptConfig { @Bean public EruptButtonModel clearDataButton() { return EruptButtonModel.builder() .setTitle("清空数据") .setFetchMethod("/erupt-api/user/clearData") .setType(EruptButtonModel.Type.TIPS) .setMessage("你确认要清空所有数据吗?此操作不可恢复!") .setIcon(new FontAwesomeIcon("fa fa-trash", Icon.Color.RED)) .build(); } } ``` 注意,这里的 `fetchMethod` 属性是指定了按钮点击后将会触发的请求的路径。在这个路径中,需要定义一个处理请求的控制器方法。 3. 在控制器中,添加一个处理按钮请求的方法: ```java @RestController @RequestMapping("/erupt-api/user") public class UserController { @Autowired private UserService userService; @PostMapping("/clearData") public void clearData() { userService.clearData(); } } ``` 这里的 `UserService` 是你自己定义的服务类,用于处理具体的业务逻辑。 4. 最后,在你的页面中,使用 `erupt-buttons` 标签来渲染按钮: ```html <erupt-buttons :buttons="buttons"></erupt-buttons> ``` 在对应的 Vue 实例中,需要定义一个 `buttons` 对象,来指定要显示的按钮。在这个对象中,可以引用前面在 `EruptConfig` 中定义的 `EruptButtonModel`: ```javascript data() { return { buttons: [ clearDataButton ] } } ``` 至此,一个简单的自定义按钮就实现了。当用户点击按钮时,将会弹出提示框,询问用户是否确认进行清空数据操作。如果用户确认操作,将会触发后台的 `clearData` 方法进行清空数据的操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值