Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring boot @PathVariable can not validate

yeah, the same question as @PathVariable Validation in Spring 4 and Add class level validation to @Pathvariable in Spring

spring validated not work for param, throw no exception, here is my code follow by @Patrick's answer, thx for him

@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) { ....    }

but when I send null accountId, there are no exception throws... am I right, are there anyother solutions?

like image 735
vvsueprman Avatar asked Sep 12 '26 13:09

vvsueprman


1 Answers

Add the following annotation to the class worked for me.(Not to the method)

@Validated
like image 71
Subin Chalil Avatar answered Sep 15 '26 09:09

Subin Chalil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!