springboot @Valid 嵌套校验前端传过来的json参数

比如,前端传过来的json对象如下,校验phone的合法性之前的博文已经讲过了,但是要校验studentVo里面的name、age的合法性要怎么做呢?话不多说,直接上代码

{
"phone":"3333",
"studentVo":[{"name":"showDebit","age":2},{"name":"showDebit","age":18},{"name":"showDebit","age":18}]
}

1、controller的代码:

 


 2、StudentsVo类,在StudentsVo里面建一个StudentVo的List,注意List也要有get、set否则studentvo会获取不到数据,如果觉得写set,get麻烦可以加一个Lombok依赖,就可以不用写了。

 

 3、StudentVo类

 

 

 

 最后在postman里面试一下是否成功

 

 

The end!!!!
posted @ 2020-04-17 11:35  smellycats  阅读(1711)  评论(0编辑  收藏  举报