SSH 常见权限设计一
来源:互联网 发布:骑士夺冠 知乎 编辑:程序博客网 时间:2024/05/29 17:57
一、如图:
二、类:
1、用户user:
public class User { private Long id; private Department department; private Set<Role> roles = new HashSet<Role>(); private String loginName; // 登录名 private String password; // 密码 private String name; // 真实姓名 private String gender; // 性别 private String phoneNumber; // 电话号码 private String email; // 电子邮件 private String description; // 说明
2、部门department:
public class Department { private Long id; private Set<User> users = new HashSet<User>(); private Department parent; private Set<Department> children = new HashSet<Department>(); private String name; private String description;
3、角色role:
public class Role { private Long id; private String name; private String description; private Set<User> users = new HashSet<User>(); private Set<Privilidge> privilidges = new HashSet<Privilidge>();
4、权限prilidge:
public class Privilidge { private Long id; private String url; private String name; private String icon; private Set<Role> roles = new HashSet<Role>(); private Privilidge parent; private Set<Privilidge> children = new HashSet<Privilidge>();
三、相关的关联xml文件:
1、user.hbm.xml:
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="cn.oppo.oa.domain"> <class name="User" table="oa_user"> <id name="id"> <generator class="native"/> </id> <property name="loginName"/> <property name="password"/> <property name="name"/> <property name="gender" /> <property name="phoneNumber"/> <property name="email"/> <property name="description"/> <!-- department属性,本类与Department的多对一 --> <many-to-one name="department" class="Department" column="departmentId"></many-to-one> <!-- roles属性,本类与Role的多对多 --> <set name="roles" table="oa_user_role"> <key column="userId"></key> <many-to-many class="Role" column="roleId"></many-to-many> </set> </class></hibernate-mapping>
2、department.hbm.xml
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="cn.oppo.oa.domain"> <class name="Department" table="oa_department"> <id name="id"> <generator class="native" /> </id> <property name="name" /> <property name="description" /> <!-- users属性,本类与User的一对多 --> <set name="users"> <key column="departmentId"></key> <one-to-many class="User" /> </set> <!-- parent属性,本类与Department(上级)的多对一 --> <many-to-one name="parent" class="Department" column="parentId"></many-to-one> <!-- children属性,本类与Department(下级)的一对多 --> <set name="children" cascade="delete" order-by="id ASC"> <key column="parentId"></key> <one-to-many class="Department" /> </set> </class></hibernate-mapping>
3、role.hbm.xml
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="cn.oppo.oa.domain"> <class name="Role" table="oa_role"> <id name="id"> <generator class="native"/> </id> <property name="name"/> <property name="description"/> <!-- users属性,本类与User的多对多 --> <set name="users" table="oa_user_role"> <key column="roleId"></key> <many-to-many class="User" column="userId"></many-to-many> </set> </class></hibernate-mapping>
4、权限priviledge.hbm.xml
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="cn.oppo.oa.domain"> <class name="Privilege" table="oa_privilege"> <id name="id"> <generator class="native"/> </id> <property name="url"/> <property name="name"/> <property name="icon"/> <!-- roles属性,本类与Role的多对多 --> <set name="roles" table="oa_role_privilege"> <key column="privilegeId"></key> <many-to-many class="Role" column="roleId"></many-to-many> </set> <!-- parent属性,本类与Privilege(上级)的多对一 --> <many-to-one name="parent" class="Privilege" column="parentId"></many-to-one> <!-- children属性,本类与Privilege(下级)的一对多 --> <set name="children" order-by="id" lazy="false"> <key column="parentId"></key> <one-to-many class="Privilege"/> </set> </class></hibernate-mapping>
四、hibernate配置文件
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration><session-factory> <!-- 数据库信息(连接信息写到spring的配置文件中) --> <property name="dialect">org.hibernate.dialect.SQLServer2008Dialect</property> <!-- 其他配置 --> <property name="show_sql">true</property> <property name="hbm2ddl.auto">update</property> <!-- 导入映射配置 --> <mapping resource="cn/oppo/oa/domain/User.hbm.xml" /> <mapping resource="cn/oppo/oa/domain/Role.hbm.xml" /> <mapping resource="cn/oppo/oa/domain/Department.hbm.xml" /> <mapping resource="cn/oppo/oa/domain/priviledge.hbm.xml" /> </session-factory></hibernate-configuration>
五、spring配置文件:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- 自动扫描与装配bean --> <context:component-scan base-package="cn.oppo.oa,cn.oppo.system"></context:component-scan> <!-- 加载外部的properties配置文件 --> <context:property-placeholder location="classpath:jdbc.properties" /> <!-- 配置数据库连接池(c3p0) --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <!-- 基本信息 --> <property name="jdbcUrl" value="${jdbcUrl}"></property> <property name="driverClass" value="${driverClass}"></property> <property name="user" value="${username}"></property> <property name="password" value="${password}"></property> <!-- 其他配置 --> <!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 --> <property name="initialPoolSize" value="3"></property> <!--连接池中保留的最小连接数。Default: 3 --> <property name="minPoolSize" value="3"></property> <!--连接池中保留的最大连接数。Default: 15 --> <property name="maxPoolSize" value="5"></property> <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 --> <property name="acquireIncrement" value="3"></property> <!-- 控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 --> <property name="maxStatements" value="8"></property> <!-- maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 --> <property name="maxStatementsPerConnection" value="5"></property> <!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 --> <property name="maxIdleTime" value="1800"></property> </bean> <!-- 配置SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="configLocation" value="classpath:hibernate.cfg.xml"></property> </bean> <!-- 配置声明式的事务管理(采用基于注解的方式) --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <!-- 配置定时任务 --> <bean id="SchedulerTask" class="org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass"> <value>cn.oppo.oa.helper.OrderNoRefact</value> </property> </bean> <!-- 配置定时时间 --> <bean id="SchedulerTaskTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="SchedulerTask" /> <property name="cronExpression"> <value>0 0/30 0/1 * * ?</value> </property> </bean> <!-- 开启定时任务 --> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="SchedulerTaskTrigger" /> </list> </property> </bean></beans>
六、权限安装
package cn.oppo.oa.util;import javax.annotation.Resource;import org.apache.commons.codec.digest.DigestUtils;import org.hibernate.SessionFactory;import org.hibernate.classic.Session;import org.springframework.context.support.ClassPathXmlApplicationContext;import org.springframework.stereotype.Component;import org.springframework.transaction.annotation.Transactional;import cn.oppo.oa.domain.Privilege;import cn.oppo.oa.domain.User;@Componentpublic class Installer { @Resource private SessionFactory sessionFactory; @Transactional public void install() { Session session = sessionFactory.getCurrentSession(); User user = new User(); user.setLoginName("admin"); user.setName("超级管理员"); user.setPassword(DigestUtils.md5Hex("admin")); // 保存超级用户 session.save(user); // =================================================== // 二、权限数据 Privilege menu, menu1, menu2, menu3, menu4, menu5; menu = new Privilege("系统管理", null, "FUNC20082.gif", null); menu1 = new Privilege("岗位管理", "role_list", null, menu); menu2 = new Privilege("部门管理", "department_list", null, menu); menu3 = new Privilege("用户管理", "user_list", null, menu); session.save(menu); session.save(menu1); session.save(menu2); session.save(menu3); session.save(new Privilege("岗位列表", "role_list", null, menu1)); session.save(new Privilege("岗位删除", "role_delete", null, menu1)); session.save(new Privilege("岗位添加", "role_add", null, menu1)); session.save(new Privilege("岗位修改", "role_edit", null, menu1)); session.save(new Privilege("部门列表", "department_list", null, menu2)); session.save(new Privilege("部门删除", "department_delete", null, menu2)); session.save(new Privilege("部门添加", "department_add", null, menu2)); session.save(new Privilege("部门修改", "department_edit", null, menu2)); session.save(new Privilege("用户列表", "user_list", null, menu3)); session.save(new Privilege("用户删除", "user_delete", null, menu3)); session.save(new Privilege("用户添加", "user_add", null, menu3)); session.save(new Privilege("用户修改", "user_edit", null, menu3)); session.save(new Privilege("用户初始化密码", "user_initPassword", null, menu3)); // ------------------------- menu = new Privilege("网上交流", null, "FUNC20064.gif", null); menu1 = new Privilege("论坛管理", "forumManage_list", null, menu); menu2 = new Privilege("论坛", "forum_list", null, menu); session.save(menu); session.save(menu1); session.save(menu2); // ------------------------- menu = new Privilege("审批流转", null, "FUNC20057.gif", null); menu1 = new Privilege("审批流程管理", "processDefinition_list", null, menu); menu2 = new Privilege("申请模板管理", "applicationTemplate_list", null, menu); menu3 = new Privilege("起草申请", "flow_applicationTemplateList", null, menu); menu4 = new Privilege("待我审批", "flow_myTaskList", null, menu); menu5 = new Privilege("我的申请查询", "flow_myApplicationList", null, menu); session.save(menu); session.save(menu1); session.save(menu2); session.save(menu3); session.save(menu4); session.save(menu5); } public static void main(String[] args) { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml"); Installer installer = (Installer) applicationContext.getBean("installer"); installer.install(); }}
0 0
- SSH 常见权限设计一
- SSH 常见权限设计二
- SSH 常见权限设计五:权限分类
- 常见模块设计--权限管理(一)
- SSH 常见权限设计三:左侧菜单展示
- 权限管理设计一
- 权限管理设计一
- 权限管理设计一
- 权限管理设计一
- SSH 常见权限设计四:如何得到<s:a action="url">kkk</s:a>里面的url
- ssh中常见的异常(一)
- 常见的权限管理设计之一
- 常见的权限管理设计之二
- 权限设计学习(一)
- 权限管理设计(一)
- 权限管理设计(一)
- ssh权限
- ssh中关于权限管理的设计技巧
- iOS-Main-(常规RAC演练)
- 【NOIP2016提高A组五校联考1】排队
- java中的设计模式的学习?单例模式
- 事务的隔离级别
- 试题:基本算法题之【求1!+2!+3!+...+n!】
- SSH 常见权限设计一
- 单片机==数码管+蜂鸣器+炸弹(15)
- iOS-Main-(RAC演练)-循环引用
- 【C++研发面试笔记】23. 面向对象设计模式
- 最长下降子序列优化
- 如何关闭Eclipse按空格和等号键自动补全内容
- hdu 1286找新朋友
- 浅谈JavaScript中浏览器兼容的问题
- Javascript-类(一)