首页 > 代码库 > 【JeeSite】角色和权限的修改
【JeeSite】角色和权限的修改
@RequiresPermissions("sys:role:edit") @RequestMapping(value = "save") public String save(Role role, Model model, RedirectAttributes redirectAttributes) { if(!UserUtils.getUser().isAdmin()&&role.getSysData().equals(Global.YES)){ addMessage(redirectAttributes, "越权操作,只有超级管理员才能修改此数据!"); return "redirect:" + adminPath + "/sys/role/?repage"; } if(Global.isDemoMode()){ addMessage(redirectAttributes, "演示模式,不允许操作!"); return "redirect:" + adminPath + "/sys/role/?repage"; } if (!beanValidator(model, role)){ return form(role, model); } if (!"true".equals(checkName(role.getOldName(), role.getName()))){ addMessage(model, "保存角色‘" + role.getName() + "‘失败, 角色名已存在"); return form(role, model); } if (!"true".equals(checkEnname(role.getOldEnname(), role.getEnname()))){ addMessage(model, "保存角色‘" + role.getName() + "‘失败, 英文名已存在"); return form(role, model); } systemService.saveRole(role); addMessage(redirectAttributes, "保存角色‘" + role.getName() + "‘成功"); return "redirect:" + adminPath + "/sys/role/?repage"; } ======================================== @Transactional(readOnly = false) public void saveRole(Role role) { if (StringUtils.isBlank(role.getId())){ role.preInsert(); roleDao.insert(role); // 同步到Activiti saveActivitiGroup(role); }else{ role.preUpdate(); roleDao.update(role); } // 更新角色与菜单关联 roleDao.deleteRoleMenu(role); if (role.getMenuList().size() > 0){ roleDao.insertRoleMenu(role); } // 更新角色与部门关联 roleDao.deleteRoleOffice(role); if (role.getOfficeList().size() > 0){ roleDao.insertRoleOffice(role); } // 同步到Activiti saveActivitiGroup(role); // 清除用户角色缓存 UserUtils.removeCache(UserUtils.CACHE_ROLE_LIST); // // 清除权限缓存 // systemRealm.clearAllCachedAuthorizationInfo(); }
页面传参数menuIds , 数据库保存用的参数是menuList, 中间通过setMenuIds--->setMenuIdList---->menuList
public List<String> getMenuIdList() { List<String> menuIdList = Lists.newArrayList(); for (Menu menu : menuList) { menuIdList.add(menu.getId()); } return menuIdList; } public void setMenuIdList(List<String> menuIdList) { menuList = Lists.newArrayList(); for (String menuId : menuIdList) { Menu menu = new Menu(); menu.setId(menuId); menuList.add(menu); } } public String getMenuIds() { return StringUtils.join(getMenuIdList(), ","); } public void setMenuIds(String menuIds) { menuList = Lists.newArrayList(); if (menuIds != null){ String[] ids = StringUtils.split(menuIds, ","); setMenuIdList(Lists.newArrayList(ids)); } }
只贴出保存权限的,角色的省略,sql语句有点变态,很长很长,这里只是对生成的sql语句截取部分
<insert id="insertRoleMenu"> INSERT INTO sys_role_menu(role_id, menu_id) <foreach collection="menuList" item="menu" separator=" union all "> SELECT #{id}, #{menu.id} <if test="dbName != ‘mssql‘"> FROM dual </if> </foreach> </insert> ========================================== INSERT INTO sys_role_menu(role_id, menu_id) SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual
节点的值在保存提交的时候存在这里,
<form:hidden path="menuIds"/>
<form:hidden path="officeIds"/>
submitHandler: function(form){ var ids = [], nodes = tree.getCheckedNodes(true); for(var i=0; i<nodes.length; i++) { ids.push(nodes[i].id); } $("#menuIds").val(ids); var ids2 = [], nodes2 = tree2.getCheckedNodes(true); for(var i=0; i<nodes2.length; i++) { ids2.push(nodes2[i].id); } $("#officeIds").val(ids2); loading(‘正在提交,请稍等...‘); form.submit(); },
有个地方注意一点,在roleDao.xml 的get 方法中,column="officeList.id" , 因为后面命名了 ro.office_id AS "officeList.id":
<collection property="officeList" ofType="Office">
<id property="id" column="officeList.id" />
</collection>
【JeeSite】角色和权限的修改
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。