use of com.luoxiao.model.UserRole 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.UserRole in project ssm_shiro_blog by Mandelo.
the class MainController method save.
/**
* 注册
*
* @param user
* @return
*/
@RequestMapping(value = "/user/regist", method = RequestMethod.POST)
public ModelAndView save(User user) {
ModelAndView mv = new ModelAndView();
try {
user.setStatus("1");
user.setRegTime(new Date());
userService.save(user);
Integer id = user.getId();
System.out.println(id);
/* UserRole userRole = userRoleService.selectByUserId(id); */
UserRole userRole = new UserRole();
userRole.setUserId(id);
// 默认注册用户,RoleId即为3
userRole.setRoleId(3);
userRoleService.insert(userRole);
mv.setViewName("success/registSuccess");
} catch (Exception e) {
mv.setViewName("error/registError");
e.printStackTrace();
}
mv.addObject("user", userService.selectById(user.getId()));
return mv;
}
Aggregations