Python 官方文档:入门教程 => 点击学习
目录一:引入依赖包二:在注解里标记清楚规则三:在Controller里使用@Validated注解四:调用接口验证是否生效一:引入依赖包 <!-- https://mvnrep
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-validation -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
@Data
public class Test01VO {
@NotNull(message = "ID不能为空")
private Integer id;
@Min(0)
@Max(5)
private Integer score;
private String content;
}
@PostMapping("/test01")
public String test(@Validated @RequestBody Test01VO test01vo) {
System.out.print("test>>>>>>>>>"+test01vo.getId());
return "success";
}
参数:
{
"id": "",
"score": 5
}
返回参数异常:
{
"code": 410,
"msg": "ID不能为空; ",
"data": null,
"traceId": null
}
参数:
{
"id": "1",
"score": "10"
}
返回参数异常:
{
"code": 410,
"msg": "must be less than or equal to 5; ",
"data": null,
"traceId": null
}
参数:
{
"id": "1",
"score": 5
}
返回值:
success
以上就是使用注解@Validated效验VO参数是否合规的详细内容,更多关于@Validated效验VO参数的资料请关注编程网其它相关文章!
--结束END--
本文标题: 使用注解@Validated效验VO参数是否合规
本文链接: https://lsjlt.com/news/214084.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0