Search in sources :

Example 1 with UserRoleTemp

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;
}
Also used : User(com.luoxiao.model.User) UserRoleTemp(com.luoxiao.model.UserRoleTemp) UserRole(com.luoxiao.model.UserRole) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with UserRoleTemp

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;
}
Also used : User(com.luoxiao.model.User) UserRoleTemp(com.luoxiao.model.UserRoleTemp) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with UserRoleTemp

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;
}
Also used : User(com.luoxiao.model.User) UserRoleTemp(com.luoxiao.model.UserRoleTemp) ArrayList(java.util.ArrayList) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

User (com.luoxiao.model.User)3 UserRoleTemp (com.luoxiao.model.UserRoleTemp)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 UserRole (com.luoxiao.model.UserRole)1 ArrayList (java.util.ArrayList)1