Esempio n. 1
0
  @RequestMapping(value = "edit.html", method = RequestMethod.POST)
  public String edit(@ModelAttribute("employee") Employee employee, HttpServletRequest request) {
    Validator validator = new Validator();
    validator
        .isNotBlankValidator(employee.getAccount(), "请填写用户名")
        .isNotBlankValidator(employee.getDepartment(), "轻填写部门")
        .isNotBlankValidator(employee.getEmail(), "请填写邮件")
        .isNotBlankValidator(employee.getMobile(), "请填写手机号码")
        .isNotBlankValidator(employee.getPassword(), "请填写用户密码");
    // check user name
    if (employee.getId() == null) {
      if (employeeService.getEmployeeByAccount(employee.getAccount()) != null) {
        validator.expressionValidator(true, "用户账户不能重复");
      }
    }

    if (StringUtils.isNotEmpty(validator.renderHtmlMessage())) {
      request.setAttribute("message", validator.renderHtmlMessage());
    } else {
      if (employee.getId() == null) {
        employee.setCreatedAt(new Date());
        employee.setUpdatedAt(new Date());
        employeeService.save(employee);
        request.setAttribute("message", "用户信息增加成功");
      } else {
        employee.setUpdatedAt(new Date());
        employeeService.update(employee);
        request.setAttribute("message", "用户信息修改成功");
      }
    }
    return "admin/employee/edit";
  }
Esempio n. 2
0
 @RequestMapping(value = "doEdit.html", method = RequestMethod.GET)
 public String doEdit(Employee employee, HttpServletRequest request) {
   if (employee.getId() != null) {
     employee = employeeService.getEmployee(employee.getId());
     request.setAttribute("model", employee);
   }
   return "admin/employee/edit";
 }