码迷,mamicode.com
首页 > 编程语言 > 详细

EasyUI 角色授权(SpringMVC+Hibernate)

时间:2015-05-21 12:47:37      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:easyui   权限管理   授权   

系统中,角色表和操作表是多对多的关系,总体思路就是先显示出系统的可分配的菜单和操作(就是权限),然后显示该角色已经拥有的权限,即发送两次请求,就是下面这样:

技术分享技术分享技术分享

然后你要授权就勾选,按下授权按钮,向后台传输的数据其实很简单那,就是该角色的ID(roleId)和所授权权限的ID集合(ids):

	var submitForm = function($dialog, $grid, $pjq) {
		var nodes = $('#tree').tree('getChecked', [ 'checked', 'indeterminate' ]);
		var ids = [];
		for (var i = 0; i < nodes.length; i++) {
			ids.push(nodes[i].id);
		}
		$.post('role/grantRole', {
			roleId : $('#roleId').val(),
			ids : ids.join(',')
		}, function(result) {
			if (result.success) {
				$dialog.dialog('destroy');
			} else {
				$pjq.messager.alert('提示', result.msg, 'error');
			}
			$pjq.messager.alert('提示', '授权成功!', 'info');
		}, 'json');
	};

然后后台接受,在遍历权限集合,把每个权限都添加到该角色上就行了.

Controller:

	  @RequestMapping("/grantRole")
	  public void grantRole(HttpServletRequest request,HttpServletResponse response){
		  int roleId =  Integer.valueOf(request.getParameter("roleId")) ;
		  String ids=request.getParameter("ids");
		  System.out.println(ids);
		  roleService.grant(roleId,ids);
		  Json json = new Json();
		  json.setSuccess(true);
		  writeJson(json,response);
		}
		

Service中的  roleService.grant(roleId,ids):
	public void grant(int roleId, String ids) {
		// TODO Auto-generated method stub
		Role role=roleDao.getById(Role.class, roleId);
		if(role!=null){
			role.setOpeations(new HashSet<Operation>());
			for(String operationId: ids.split(",")){
				if (!StringUtils.isBlank(operationId)){
					Operation o=operationDao.getById(Operation.class, operationId);
					if(o!=null){
						role.getOpeations().add(o);
					}
				}
			}
		}
	}
	





EasyUI 角色授权(SpringMVC+Hibernate)

标签:easyui   权限管理   授权   

原文地址:http://blog.csdn.net/yang362046076/article/details/45889079

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!