对象参数校验——注解方式

注解方式:(单用或者混用)

JSR和Hibernate validator的校验只能对Object的属性进行校验

spring validator添加了MethodValidationPostProcessor拦截器,可以实现对方法参数的校验

一、Spring Validator

'org.springframework.boot.spring-boot-starter-validation<'

https://docs.spring.io/spring/docs/5.0.5.RELEASE/spring-framework-reference/core.html#validation-beanvalidation

二、Hibernate Validator

'javax.validation:validation-api:2.0.1.Final'
'org.hibernate.validator:hibernate-validator:6.0.16.Final'

https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#preface

https://www.cnblogs.com/albert1024/articles/8436270.html

可用:https://www.jianshu.com/p/ca0bac07f473  ——接口方法的参数添加 @Valid,接口实现类添加 @Validated,需要校验的实体类参数上添加注解

 

 

注:

spring boot自定义注解+AOP拦截:https://blog.csdn.net/piaoranyuji/article/details/89448632

注解解释比较全:https://blog.csdn.net/HunterUUU/article/details/85253408

示例看着不错的:https://blog.csdn.net/steven2xupt/article/details/87452664

https://blog.csdn.net/justry_deng/article/details/86571671

写的比较乱,但也算是全的,不过尽量不要看这个吧,难受:https://www.cnblogs.com/cjsblog/p/8946768.html

你可能感兴趣的:(java)