簡體   English   中英

不拋出MethodArgumentNotValidException

[英]MethodArgumentNotValidException not thrown

我的控制器如下所示:

@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應該在驗證期間拋出該異常?

如果我沒記錯的話, 只有在沒有為@Valid注釋的參數提供Errors (此處為BindingResult )參數時,Spring 才會拋出MethodArgumentNotValidException

如果你願意,你可以自己扔掉它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM