public void update(int id, String roleName, String roleNote, String[] rolePermission) { Role role = new Role(roleName, roleNote); roleDaoImpl.update(role, id); // 更新角色信息 rolePermissionDaoImpl.deleteRolePermissionWithRoleId(id); // 先删除RoleId对应的权限 int permissionId = 1; for (String permission : rolePermission) { permissionId = Integer.parseInt(permission); rolePermissionDaoImpl.addRolePermission(id, permissionId); // 重新加入权限 } }
public void addRole(String roleName, String roleNote, String[] rolePermissions) { Role role = new Role(roleName, roleNote); roleDaoImpl.addRole(role); int permissionID = -1; for (String permissionId : rolePermissions) { permissionID = Integer.parseInt(permissionId); rolePermissionDaoImpl.addRolePermission(role.getRoleId(), permissionID); } }
public List<Permission> getRolePermissions(int id) { List<Permission> permissionForRole = new ArrayList<Permission>(); // 角色拥有的权限 List<RolePermission> rolePermissions = rolePermissionDaoImpl.getRolePermissions(id); Permission permission = null; for (RolePermission rolePermission : rolePermissions) { int permissionId = rolePermission.getPermissionId(); permission = permissionDaoImpl.getPermission(permissionId); permissionForRole.add(permission); } return permissionForRole; }
public void delete(int roleId) { userRoleDaoImpl.deleteWithRoleId(roleId); rolePermissionDaoImpl.deleteRolePermissionWithRoleId(roleId); roleDaoImpl.delete(roleId); }