示例#1
0
 @RequestMapping(value = "/modify/{userid}", method = RequestMethod.POST)
 public String modifyUser(
     @ModelAttribute("userBean") UserFormBean userBean,
     @PathVariable Integer userid,
     Model model) {
   User u = userService.getUserById(userid);
   userBean.setUserId(u.getUserId());
   userBean.setCreatedBy(u.getCreatedBy());
   userService.modifyUser(userFrom2user(u, userBean));
   return "redirect:/user";
 }
示例#2
0
 @RequestMapping(value = "/modify/{userid}", method = RequestMethod.GET)
 public String modifyUser(@PathVariable Integer userid, Model model) {
   UserFormBean formBean = new UserFormBean();
   User user = userService.getUserById(userid);
   BeanUtils.copyProperties(user, formBean);
   if (user.getRoles() != null && user.getRoles().size() > 0) {
     Set<String> roleNames = new HashSet<String>();
     for (Role role : user.getRoles()) {
       roleNames.add(role.getRoleName());
     }
     formBean.setRoleNames(roleNames);
   }
   model.addAttribute("userBean", formBean);
   model.addAttribute("roles", roleService.findAll());
   return "user/modify";
 }
示例#3
0
  private User userFrom2user(User user, UserFormBean userBean) {
    BeanUtils.copyProperties(userBean, user);

    if (userBean.getRoleNames() != null) {
      List<Role> roleList = new ArrayList<Role>();

      for (Role role : roleService.findAll()) {
        for (String roleName : userBean.getRoleNames()) {
          if (roleName.equals(role.getRoleName())) {
            roleList.add(role);
          }
        }
      }
      user.setRoles(roleList);
    }
    return user;
  }