use of com.luoxiao.model.UserRoleTemp in project ssm_shiro_blog by Mandelo.
the class MainController method updateRoles.
/**
* 修改角色roles,并保存
*
* @param userId
* @return
*/
@ResponseBody
@RequestMapping(value = "/updateRoles", method = RequestMethod.GET)
public UserRoleTemp updateRoles(@RequestParam(value = "userId") Integer userId, @RequestParam(value = "roleStr") String roleStr) {
UserRoleTemp u = new UserRoleTemp();
System.out.println(roleStr);
// 根据用户userId删除所有RoleId
userRoleService.deleteById(userId);
// 遍历角色名
String[] roleNames = roleStr.split(",");
for (int i = 0; i < roleNames.length; i++) {
Integer roleId = (roleService.getIdByRoleName(roleNames[i]));
// 插入新的数据到UserRole表
UserRole userRole = new UserRole();
userRole.setUserId(userId);
userRole.setRoleId(roleId);
userRoleService.insert(userRole);
}
User user = userService.selectById(userId);
List<String> roles = userExtendService.getRoles(user.getUsername());
u.setId(userId);
u.setRoles(roles);
u.setUsername(user.getUsername());
return u;
}
use of com.luoxiao.model.UserRoleTemp in project ssm_shiro_blog by Mandelo.
the class MainController method roleManage.
/**
* 用户角色管理
*
* @param userId
* @return
*/
@ResponseBody
@RequestMapping(value = "/getRoles")
public UserRoleTemp roleManage(@RequestParam(value = "userId") Integer userId) {
UserRoleTemp u = new UserRoleTemp();
User user = userService.selectById(userId);
List<String> roles = userExtendService.getRoles(user.getUsername());
u.setId(userId);
u.setRoles(roles);
u.setUsername(user.getUsername());
return u;
}
use of com.luoxiao.model.UserRoleTemp in project ssm_shiro_blog by Mandelo.
the class MainController method getUserRoleList.
@ResponseBody
@RequestMapping("/cms/userRoleList")
public List<UserRoleTemp> getUserRoleList() {
List<User> userList = userService.selectAll();
List<UserRoleTemp> userRoleList = new ArrayList<UserRoleTemp>();
for (User user : userList) {
List<String> roleList = userExtendService.getRoles(user.getUsername());
UserRoleTemp u = new UserRoleTemp();
u.setId(user.getId());
u.setUsername(user.getUsername());
u.setRoles(roleList);
userRoleList.add(u);
}
return userRoleList;
}
Aggregations