示例#1
0
  /**
   * 验证返回格式 单个:[fieldId, 1|0, msg] 多个:[[fieldId, 1|0, msg],[fieldId, 1|0, msg]]
   *
   * @param fieldId
   * @param fieldValue
   * @return
   */
  @RequestMapping(value = "validate", method = RequestMethod.GET)
  @ResponseBody
  public Object validate(
      @RequestParam("fieldId") String fieldId,
      @RequestParam("fieldValue") String fieldValue,
      @RequestParam(value = "id", required = false) Long id) {
    ValidateResponse response = ValidateResponse.newInstance();

    if ("name".equals(fieldId)) {
      Sample sample = getSampleService().findByName(fieldValue);
      if (sample == null || (sample.getId().equals(id) && sample.getName().equals(fieldValue))) {
        // 如果msg 不为空 将弹出提示框
        response.validateSuccess(fieldId, "");
      } else {
        response.validateFail(fieldId, "该名称已被其他人使用");
      }
    }
    return response.result();
  }
示例#2
0
  /**
   * 验证返回格式 单个:[fieldId, 1|0, msg] 多个:[[fieldId, 1|0, msg],[fieldId, 1|0, msg]]
   *
   * @param fieldId
   * @param fieldValue
   * @return
   */
  @RequestMapping(value = "validate", method = RequestMethod.GET)
  @ResponseBody
  public Object validate(
      @RequestParam("fieldId") String fieldId,
      @RequestParam("fieldValue") String fieldValue,
      @RequestParam(value = "id", required = false) Long id) {
    ValidateResponse response = ValidateResponse.newInstance();

    if ("key".equals(fieldId)) {
      KeyValue keyValue = getKeyValueService().findByKey(fieldValue);
      if (keyValue == null
          || (keyValue.getId().equals(id) && keyValue.getKey().equals(fieldValue))) {
        // 如果msg 不为空 将弹出提示框
        response.validateSuccess(fieldId, "");
      } else {
        response.validateFail(fieldId, "该键已被使用");
      }
    }
    return response.result();
  }