Beispiel #1
0
  /**
   * 验证失败返回true
   *
   * @param m
   * @param result
   * @return
   */
  @Override
  protected boolean hasError(Sample m, BindingResult result) {
    Assert.notNull(m);

    // 字段错误 前台使用<es:showFieldError commandName="showcase/sample"/> 显示
    if (m.getBirthday() != null && m.getBirthday().after(new Date())) {
      // 前台字段名(前台使用[name=字段名]取得dom对象) 错误消息键。。
      result.rejectValue("birthday", "birthday.past");
    }

    // 全局错误 前台使用<es:showGlobalError commandName="showcase/sample"/> 显示
    if (m.getName().contains("admin")) {
      result.reject("name.must.not.admin");
    }

    return result.hasErrors();
  }