springboot使用注解做参数校验

2025-05-21 05:47:39

1、一、参数检验中最传统的做法

springboot使用注解做参数校验

2、二、使用avax.validation.constraints包下的注解进行参数校验1.引入依赖

springboot使用注解做参数校验

3、2.定义参数对象类StudentParam,使用注解进行属性校验

springboot使用注解做参数校验

4、3.在Controller中的方法上,将StudentParam对象作为参数。在参数前使用@Valid注解,否则不会去校验。@V锾攒揉敫alid必须在参数前面且相邻。这样在请求Controller的方法就会去校验参数了。

springboot使用注解做参数校验

5、使用postman 请求效果如下图

springboot使用注解做参数校验

6、javax.validation.constraints包下常用的注解

springboot使用注解做参数校验
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢