spring boot @PathVariable 无法验证

vvs*_*man 0 validation spring spring-boot

是的,与Spring 4 中的 @PathVariable Validation和Add class level validation to @Pathvariable in Spring相同的问题

spring 验证不适用于参数,抛出也不例外,这是我的代码,后面是@Patrick 的回答,感谢他

@Bean
public MethodValidationPostProcessor methodValidationPostProcessor() {
     return new MethodValidationPostProcessor();
}

/**
 * 
 * @param accountId
 */
@RequestMapping(value="/orderDetailSelByAccountId/{accountId}.json",method= {RequestMethod.POST})
@ResponseBody
@Validated
public Result<?> orderDetailSelByAccountId(  @NotNull @NotBlank 
@Size(min=10,max=32)@PathVariable(value="accountId") String accountId) { ....    }
Run Code Online (Sandbox Code Playgroud)

但是当我发送空 accountId 时,没有异常抛出......我是对的,还有其他解决方案吗?

Sub*_*lil 5

将以下注释添加到为我工作的类中。(不是方法)

@Validated
Run Code Online (Sandbox Code Playgroud)