@ Validated and @ Valid Exception Catch Handling
- 2021-11-30 00:20:52
- OfStack
Directories @ Validated and @ Valid Exception Capture Exceptions There are 3 different annotation locations for @ Valid and @ Validated
@ Validated and @ Valid Exception Trap
There are 3 kinds of anomalies
BindException
Form submission is valid, but it will not be valid for submission in json format
MethodArgumentNotValidException
The preceding paragraph is valid in json format
ConstraintViolationException
Add @ RequestParam to the parameter or @ NotBlank @ NotNull to the parameter, etc
The difference between @ Valid and @ Validated
@Valid
Is used when using Hibernate validation
@Validated
Is used only by the Spring Validator verification mechanism
Explanation: JSR303 of java declares an interface like @ Valid, and Hibernate-validator implements it
@ Validation encapsulates @ Valid twice. There is no difference in use, but there are differences in grouping, annotation position, nesting verification and other functions. Here, these situations are mainly explained.
Annotation position
@Validated
Used on types, methods, and method parameters. But not for member properties (field)
@Valid
Can be used on methods, constructors, method parameters, and member properties (field)