Spring+Struts2+ExtJs权限管理的设计(一)数据库的设计
1、本系统的后台使用MySQL数据库,SSH 框架,前端使用ExtJs实现。因为系统需要用到权限管理,所以作此记录,权限管理精确到前端的每一个按钮,甚至每一个action请求。
成都创新互联,为您提供成都网站建设、网站制作、网站营销推广、网站开发设计,对服务成都楼梯护栏等多个行业拥有丰富的网站建设及推广经验。成都创新互联网站建设公司成立于2013年,提供专业网站制作报价服务,我们深知市场的竞争激烈,认真对待每位客户,为客户提供赏心悦目的作品。 与客户共同发展进步,是我们永远的责任!
废话不多说,直接进入主题
(一)、数据库的设计
权限管理部分总共包括4个数据表:
Power(记录权限)、 Role(记录角色)、 PowerRole(中间表)、 PowerUrl(记录每一个action请求或者前端按钮)
(Role表)
package com.txb.model;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table(name="TB_ROLE")
public class Role {
private int roleId;
private String roleName;
private Set
private Set
@Id
@Column(name = "ROLE_ID", insertable = false, updatable = false, nullable = false, unique = true)
@GeneratedValue(strategy=GenerationType.AUTO)
public int getroleId() {
return roleId;
}
public void setroleId(int roleId) {
this.roleId = roleId;
}
@Column(name = "role_NAME", nullable = false, length = 50)
public String getroleName() {
return roleName;
}
public void setroleName(String roleName) {
this.roleName = roleName;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "role")
public Set
return rolePowers;
}
public void setrolePowers(Set
this.rolePowers = rolePowers;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "role")
public Set
return adminRoles;
}
public void setAdminroles(Set
this.adminRoles = adminRoles;
}
}
(Power表)
package com.txb.model;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table(name="TB_POWER")
public class Power {
private int powerId;
private String powerName;
private String powerType;
private String menu; //菜单
private Set
private Set
@Id
@Column(name = "POWER_ID", insertable = false, updatable = false, nullable = false, unique = true)
@GeneratedValue(strategy=GenerationType.AUTO)
public int getPowerId() {
return powerId;
}
public void setPowerId(int powerId) {
this.powerId = powerId;
}
@Column(name="POWER_NAME", nullable = false, length = 50)
public String getPowerName() {
return powerName;
}
public void setPowerName(String powerName) {
this.powerName = powerName;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "power")
public Set
return rolePowers;
}
public void setRolePowers(Set
this.rolePowers = rolePowers;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "power")
public Set
return actionUrls;
}
public void setActionUrls(Set
this.actionUrls = actionUrls;
}
@Column(name="POWER_TYPE", nullable = false, length = 10)
public String getPowerType() {
return powerType;
}
public void setPowerType(String powerType) {
this.powerType = powerType;
}
@Column(name="POWER_MENU", nullable = true, length = 10)
public String getMenu() {
return menu;
}
public void setMenu(String menu) {
this.menu = menu;
}
}
(Role - Power 中间表,因为他们是多对多的关系)
package com.txb.model;
import java.io.Serializable;
import javax.persistence.*;
/**
* The persistent class for the rose_power database table.
*
*/
@Entity
@Table(name="TB_ROLE_POWER")
public class RolePower implements Serializable {
private int rpid;
private Power power;
private Role role;
public RolePower() {
}
@Id
@Column(name = "RP_ID", insertable = false, updatable = false, nullable = false, unique = true)
@GeneratedValue(strategy=GenerationType.AUTO)
public int getRpid() {
return this.rpid;
}
public void setRpid(int rpid) {
this.rpid = rpid;
}
@ManyToOne
@JoinColumn(name="POWER_ID")
public Power getPower() {
return this.power;
}
public void setPower(Power power) {
this.power = power;
}
@ManyToOne
@JoinColumn(name="ROLE_ID")
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
}
}
(PowerUrl 表,这个表是用来记录每一个action请求,判断该用户所拥有的权限是否能执行对应的action请求)
package com.txb.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name="TB_ACTION_URL")
public class ActionUrl {
private Power power;
private String url;
private String actionName;
private int aId;
@ManyToOne
@JoinColumn(name="POWER_ID")
public Power getPower() {
return power;
}
public void setPower(Power power) {
this.power = power;
}
@Column(name="URL", nullable = false, length = 50)
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
@Column(name="ACTION_NAME", nullable = false, length = 50)
public String getActionName() {
return actionName;
}
public void setActionName(String actionName) {
this.actionName = actionName;
}
@Id
@Column(name = "A_ID", insertable = false, updatable = false, nullable = false, unique = true)
@GeneratedValue(strategy=GenerationType.AUTO)
public int getaId() {
return aId;
}
public void setaId(int aId) {
this.aId = aId;
}
}
到此权限数据库就已经设计完毕,下一篇给大家介绍后台逻辑部分
本文名称:Spring+Struts2+ExtJs权限管理的设计(一)数据库的设计
网页路径:http://azwzsj.com/article/psdppp.html