Java – method parameter validation using jsr-303
•
Java
Is jsr-303 also used for method parameter validation?
If so, are there any examples online? The biggest challenge I face is how to get validators in each method With spring 3, does this mean that I have to inject almost every class with localvalidatorfactorybean?
thank you!
Solution
This sounds like an AOP (AspectJ) use case To use javax validation. Write a pointcut for the method annotated with constraints * *, inject a verifier into the aspect (possibly using spring), and use @ before or @ around to suggest that the verification be performed before the method is executed
Read AspectJ in action for reference
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码