java权限中表关系_数据表与简单java类(角色与权限)

1 class Dept //部门信息

2 {3 private intdid;4 privateString dname;5 private Emp[] emps;//一个部门有多个雇员

6 private Role role;//一个部分有一个角色

7 public Dept(intdid,String dname){8 this.did=did;9 this.dname=dname;10 }11 public voidsetEmps(Emp[] emps){12 this.emps=emps;13 }14 publicEmp[] getEmps(){15 return this.emps;16 }17 public voidsetRole(Role role){18 this.role=role;19 }20 publicRole getRole(){21 return this.role;22 }23 publicString getInfo(){24 return "【部门】did="+this.did+",dname="+this.dname;25 }26 }27 class Emp //雇员信息

28 {29 private inteid;30 privateString ename;31 privateDept dept;32 public Emp(inteid,String ename){33 this.eid=eid;34 this.ename=ename;35 }36 public voidsetDept(Dept dept){37 this.dept=dept;38 }39 publicDept getDept(){40 return this.dept;41 }42 publicString getInfo(){43 return "【雇员】eid="+this.eid+",ename="+this. ename;44 }45 }46 class Role //角色信息

47 {48 private intrid;49 privateString title;50 privateDept[] depts;51 privateAction[] actions;52 public Role(intrid,String title){53 this.rid=rid;54 this.title=title;55 }56 public voidsetDepts(Dept[] depts){57 this.depts=depts;58 }59 publicDept[] getDepts(){60 return this.depts;61 }62 public voidsetActions(Action[] actions){63 this.actions=actions;64 }65 publicAction[] getActions(){66 return this.actions;67 }68 publicString getInfo(){69 return "【角色】rid="+this.rid+",title="+this.title;70 }71 }72 class Action //权限信息

73 {74 private intaid;75 privateString title;76 privateString flag;77 privateRole[] roles;78 public Action(intaid,String title,String flag){79 this.aid=aid;80 this.title=title;81 this.flag=flag;82 }83 public voidsetRoles(Role[] roles){84 this.roles=roles;85 }86 publicRole[] getRoles(){87 return this.roles;88 }89 publicString getInfo(){90 return "【权限】aid="+this.aid+",title="+this.title+",flag="+this.flag;91 }92 }93 public classNewbegin{94 public static voidmain(String args[]) {95 //第一步:设置数据之间的关系96 //1.创建部门数据

97 Dept d10=new Dept(10,"财务部");98 Dept d20=new Dept(20,"市场部");99 //2.创建雇员数据

100 Emp e7369=new Emp(7369,"SMITH");101 Emp e7566=new Emp(7369,"ALLEN");102 Emp e7902=new Emp(7369,"FORD");103 Emp e7839=new Emp(7369,"KIND");104 Emp e7788=new Emp(7788,"SCOTT");105 //3.创建角色信息

106 Role r100=new Role(100,"管理者");107 Role r200=new Role(200,"职员层");108 //4.创建权限数据

109 Action a1000=new Action(1000,"雇员入职","emp:add");110 Action a2000=new Action(2000,"雇员晋升","emp:edit");111 Action a3000=new Action(3000,"发布公告","news:add");112 Action a6000=new Action(6000,"查看客户信息","customer:list");113 Action a7000=new Action(7000,"回防记录","customer:list");114 //5.设置角色与权限的关系

115 r100.setActions(newAction[]{a1000,a2000,a3000});116 r200.setActions(newAction[]{a6000,a7000});117 //6.设置权限与角色的关系

118 a1000.setRoles(newRole[]{r100});119 a2000.setRoles(newRole[]{r100});120 a3000.setRoles(newRole[]{r100});121 a6000.setRoles(newRole[]{r200});122 a7000.setRoles(newRole[]{r200});123 //7.设置部门和角色的关系

124 d10.setRole(r100);125 d20.setRole(r200);126 //8.设置角色和部门的关系

127 r100.setDepts(newDept[]{d10});128 r200.setDepts(newDept[]{d20});129 //9.设置雇员和部门的关系

130 e7369.setDept(d10);131 e7566.setDept(d10);132 e7902.setDept(d20);133 e7839.setDept(d20);134 e7788.setDept(d20);135 //10.设置部门与雇员的关系

136 d10.setEmps(newEmp[]{e7369,e7566});137 d20.setEmps(newEmp[]{e7902,e7839,e7788});138 //第二步:取出相应数据139 //要求可以根据一个员工找到相应的部门,以及对应的角色,以及每个角色的所有权限

140 System.out.println("1.要求可以根据一个员工找到相应的部门,以及对应的角色,以及每个角色的所有权限");141 System.out.println(e7369.getInfo());142 System.out.println("\t|-"+e7369.getDept().getInfo());143 System.out.println("\t\t|-"+e7369.getDept().getRole().getInfo());144 for(int x=0;x

148 System.out.println("2.可以根据一个角色找到具备此角色的所有部门,以及部门的所有员工");149 System.out.println(r200.getInfo());150 for(int x=0;x

157 System.out.println("3.根据一个权限列出所有具备该权限的角色以及角色的部门,部门的员工");158 System.out.println(a2000.getInfo());159 for(int x=0;x

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值