0

次のRestコントローラーがあります:

 @RestController
 public class DocumentSearchController_global 
{
@InitBinder//("TestCustomAnotation")
protected void initBinder(WebDataBinder binder) {
   binder.setValidator(new ChekAtleastOneValueValidator());

}

@RequestMapping(value = "/validator", method = RequestMethod.POST, produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE })
protected DocumentSearchResponse validatortest(@Valid @RequestBody TestCustomAnotation objDMSRequest,  Errors e, BindingResult br) throws AppException
{
    if(br.hasErrors())
        System.out.println("ERRor");
  if (e.hasErrors())
  {
      System.out.println("Got Error:      "+ e.getFieldError());
  }
    DocumentSearchResponse objDocSearchResponse =  null;


    return objDocSearchResponse;
    }




@ExceptionHandler
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
public String handleMethodArgumentNotValidException(
        MethodArgumentNotValidException  error) {
    System.out.println("ERROR-->>>>>>>>>>>>>>>>>>>>>>>>" +error.getMessage());
    return "Bad request: " + error.getMessage();
}
}

そして、これはリクエストがキャストされる Bean です。

        public class TestCustomAnotation
        {
        @ValidDocumentModifiedDate({"7Days", "30Days","60Days"})
        String docModifiedDate;
        @NotNull
        String objectId;
        @NotNull
        String jobId;

        Setter and GEtter
        }
  1. コントローラーで、コントロールを指定binder.setValidator(new ChekAtleastOneValueValidator());した 場合、 @ValidDocumentModifiedDate`ChekAtleastOneValueValidatorをチェックしません。@notnull
  2. 私が持っていない場合binder.setValidator(new ChekAtleastOneValueValidator()); 、コントロールは @notnull@ValidDocumentModifiedDate検証をチェックしますが、チェックしません ChekAtleastOneValueValidator

私の質問は次のとおりです: Spring でSpring 検証、カスタム注釈、および @notnull 注釈を使用し、すべての検証のすべてのエラーを取得する方法、または Spring が Spring バリデーターのみを使用できるようにする方法はありますか?

4

1 に答える 1