首注:本学习教程为传智播客汤阳光讲师所公布的免费OA项目视频我的文字版实践笔记,本人用此来加强巩固自己开发知识,如有网友转载,请注明。谢谢。
一 在权限类中Privilege.java中加入构造函数,以便初始化权限数据,如下:
public Privilege() {
}
public Privilege(String name, String url, Privilege parent) {
super();
this.name = name;
this.url = url;
this.parent = parent;
}
二 写一个工具类,用于初始化数据的,如下:
1 package cn.clear.oa.util; 2 3 import javax.annotation.Resource; 4 5 import org.apache.commons.codec.digest.DigestUtils; 6 import org.hibernate.Session; 7 import org.hibernate.SessionFactory; 8 import org.junit.Test; 9 import org.springframework.context.ApplicationContext; 10 import org.springframework.context.support.ClassPathXmlApplicationContext; 11 import org.springframework.stereotype.Component; 12 import org.springframework.transaction.annotation.Transactional; 13 14 import cn.clear.oa.domain.Privilege; 15 import cn.clear.oa.domain.User; 16 /** 17 * 初始化数据 18 * @ClassName: Installer 19 * @Description: TODO 20 * @author: clear 21 * @date: 2014-10-30 上午11:28:37 22 */ 23 @Component 24 public class Installer { 25 26 @Resource 27 private SessionFactory sessionFactory; 28 /** 29 * 执行安装 30 * @Title: install 31 * @Description: TODO 32 * @return: void 33 */ 34 @Transactional 35 public void install() { 36 Session session = sessionFactory.getCurrentSession(); 37 38 //保存超级管理员用户 39 User user = new User(); 40 user.setLoginName("admin"); 41 user.setName("超级管理员"); 42 user.setPassword(DigestUtils.md5Hex("admin")); 43 session.save(user); 44 45 //保存权限数据 46 Privilege menu,menu1,menu2,menu3,menu4,menu5; 47 //-------- 48 menu = new Privilege("系统管理", null, null); 49 menu1 = new Privilege("岗位管理", "/role_list", menu); 50 menu2 = new Privilege("部门管理", "/department_list", menu); 51 menu3 = new Privilege("用户管理", "/user_list", menu); 52 53 session.save(menu); 54 session.save(menu1); 55 session.save(menu2); 56 session.save(menu3); 57 58 session.save(new Privilege("岗位列表", "/role_list", menu1)); 59 session.save(new Privilege("岗位添加", "/role_add", menu1)); 60 session.save(new Privilege("岗位修改", "/role_edit", menu1)); 61 session.save(new Privilege("岗位删除", "/role_delete", menu1)); 62 63 session.save(new Privilege("部门列表", "department_list", menu2)); 64 session.save(new Privilege("部门添加", "department_add", menu2)); 65 session.save(new Privilege("部门修改", "department_edit", menu2)); 66 session.save(new Privilege("部门删除", "department_delete", menu2)); 67 68 session.save(new Privilege("用户列表", "user_list", menu3)); 69 session.save(new Privilege("用户添加", "user_add", menu3)); 70 session.save(new Privilege("用户修改", "user_edit", menu3)); 71 session.save(new Privilege("用户删除", "user_delete", menu3)); 72 session.save(new Privilege("初始化密码", "user_initPassword", menu3)); 73 74 //-------- 75 menu = new Privilege("网上交流", null, null); 76 menu1 = new Privilege("论坛位管理", "/forumManage_list", menu); 77 menu2 = new Privilege("论坛", "/forum_list", menu); 78 session.save(menu); 79 session.save(menu1); 80 session.save(menu2); 81 82 //-------- 83 menu = new Privilege("审批流转", null, null); 84 menu1 = new Privilege("审批流转管理", "/processDefinition_list", menu); 85 menu2 = new Privilege("申请模板管理", "/template_list", menu); 86 menu3 = new Privilege("起草申请", "/flow_templateList", menu); 87 menu4 = new Privilege("待我审批", "/flow_myTaskList", menu); 88 menu5 = new Privilege("我的申请查询", "/flow_myApplicationList", menu); 89 90 session.save(menu); 91 session.save(menu1); 92 session.save(menu2); 93 session.save(menu3); 94 session.save(menu4); 95 session.save(menu5); 96 } 97 98 public static void main(String[] args) { 99 ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml"); 100 Installer installer = (Installer) ac.getBean("installer"); 101 installer.install(); 102 } 103 104 }
Installer.java
三 完成之后,执行main方法初始化数据到数据库。
时间: 2024-10-04 23:28:39