spring 使用@Valid校验数据出错DEBUG org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod - Failed to resolve argument 0 of type

时间:2023-03-10 07:22:42
spring 使用@Valid校验数据出错DEBUG org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod - Failed to resolve argument 0 of type

问题原因:在 @Valid 的那个参数后面紧跟着一个 BindingResult 的参数(一定要紧跟着)

参考来源:https://segmentfault.com/q/1010000008384686

正确的参数签名

    @PostMapping("publishPost.do")
public String publishPost(@Valid @ModelAttribute Post post,
BindingResult bindingResult,
Errors errors, Model model, Integer tid,String action, RedirectAttributes attributes) {

错误的签名

//发帖
@PostMapping("publishPost.do")
public String publishPost(@Valid @ModelAttribute Post post,Integer tid,
BindingResult bindingResult,
Errors errors, Model model, String action, RedirectAttributes attributes) {