示例#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";
  }
示例#2
0
 @RequestMapping(value = "edit.html", method = RequestMethod.POST)
 public String edit(@ModelAttribute("link") Link link, HttpServletRequest request) {
   BackSession backSession =
       (BackSession) request.getSession().getAttribute(Constants.BACK_EMPLOYEE_SESSION);
   Validator validator = new Validator();
   validator.isNotBlankValidator(link.getLinkUrl(), "请填写链接URL");
   validator.isNotBlankValidator(link.getLinkText(), "请填写链接文本");
   if (StringUtils.isNotEmpty(validator.renderHtmlMessage())) {
     request.setAttribute("message", validator.renderHtmlMessage());
   } else {
     if (link.getId() == null) {
       link.setSiteId(backSession.getSiteId());
       link.setCreatedAt(new Date());
       link.setUpdatedAt(new Date());
       linkService.save(link);
       request.setAttribute("message", "链接信息增加成功");
     } else {
       link.setUpdatedAt(new Date());
       link.setSiteId(backSession.getSiteId());
       linkService.update(link);
       request.setAttribute("message", "链接信息更新成功");
     }
   }
   return "admin/link/edit";
 }