文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

Spring + Struts2 + ExtJs 权限管理的设计(一)数据库的设计

2024-04-02 19:55

关注

1、本系统的后台使用mysql数据库,SSH 框架,前端使用ExtJs实现。因为系统需要用到权限管理,所以作此记录,权限管理精确到前端的每一个按钮,甚至每一个action请求。


废话不多说,直接进入主题


(一)、数据库的设计

权限管理部分总共包括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<RolePower> rolePowers;

private Set<AdminRole> adminRoles;

@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<RolePower> getrolePowers() {

return rolePowers;

}


public void setrolePowers(Set<RolePower> rolePowers) {

this.rolePowers = rolePowers;

}


@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "role") 

public Set<AdminRole> getAdminroles() {

return adminRoles;

}


public void setAdminroles(Set<AdminRole> adminRoles) {

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<RolePower> rolePowers;

private Set<ActionUrl> actionUrls; //用户角色

@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<RolePower> getRolePowers() {

return rolePowers;

}


public void setRolePowers(Set<RolePower> rolePowers) {

this.rolePowers = rolePowers;

}


@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "power")

public Set<ActionUrl> getActionUrls() {

return actionUrls;

}


public void setActionUrls(Set<ActionUrl> actionUrls) {

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.*;



@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;

}

}


到此权限数据库就已经设计完毕,下一篇给大家介绍后台逻辑部分




阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯