org.webjars.bower
bootstrap-select
2.0.0-beta1
org.webjars
bootbox
4.4.0
org.springframework.boot
spring-boot-maven-plugin
2、项目结构
编写代码
1、编写实体类
菜单表实体类TbMenu,Spring-Data-Jpa可以根据实体类去数据库新建或更新对应的表结构,详情可以访问Spring-Data-Jpa入门
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mcy.springbootsecurity.custom.BaseEntity;
import org.springframework.data.annotation.CreatedBy;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
/**
-
菜单表
-
@author
*/
@Entity
public class TbMenu extends BaseEntity {
private String name;
private String url;
private Integer idx;
@JsonIgnore
private TbMenu parent;
@JsonIgnore
private List children=new ArrayList<>();
@Column(unique=true)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Integer getIdx() {
return idx;
}
public void setIdx(Integer idx) {
this.idx = idx;
}
@ManyToOne
@CreatedBy
public TbMenu getParent() {
return parent;
}
public void setParent(TbMenu parent) {
this.parent = parent;
}
@OneToMany(cascade=CascadeType.ALL,mappedBy=“parent”)
@OrderBy(value=“idx”)
public List getChildren() {
return children;
}
public void setChildren(List children) {
this.children = children;
}
public TbMenu(Integer id) {
super(id);
}
public TbMenu(){
super();
}
public TbMenu(String name, String url, Integer idx, TbMenu parent, List children) {
this.name = name;
this.url = url;
this.idx = idx;
this.parent = parent;
this.children = children;
}
public TbMenu(Integer integer, String name, String url, Integer idx, TbMenu parent, List children) {
super(integer);
this.name = name;
this.url = url;
this.idx = idx;
this.parent = parent;
this.children = children;
}
@Transient
public Integer getParentId() {
return parent==null?null:parent.getId();
}
}
表新建好了,下面就是实现增删改查就可以了。实现效果如下。
新增和修改菜单。
对于Bootstrap的树形表格,可以移步到:BootStrap-bable-treegrid树形表格的使用。
菜单管理实现了,下一步就是实现角色及角色对应的权限管理了。
角色及权限表SysRole,parent 为null时为角色,不为null时为权限。
package com.mcy.springbootsecurity.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mcy.springbootsecurity.custom.BaseEntity;