我的控制器如下所示:
@RequestMapping(value = "/cars/{types}", method = RequestMethod.PUT, headers = "Accept=application/json") @ResponseStatus(HttpStatus.OK) public void startEngine( @PathVariable @Min(0) String types, @RequestBody @Valid someObject request, BindingResult result) throws MethodArgumentNotValidException { if(result.hasErrors()) { System.out.println("Error"); //Should I be throwing MethodArgumentNotValidException here? And if so how? I don't know how to retrieve the first parameter for it's constructor (MethodParameter object) } //Controller code }
因此,在验证我的结果对象在验证期间是否遇到任何错误之后,我怎么能抛出MethodArgumentNotValidException?或者Spring应该在验证期间抛出该异常?