@decimalmin未验证输入
我有一个 Spring Boot 项目,我尝试验证数字输入是否大于零。我为此使用了 @DecimalMin 但不起作用。我上网并尝试了不同的方法,但似乎都不起作用。
这是代码示例:
@GetMapping("/bmi")
public ResponseEntity<BMIDto> getBMI(@RequestParam("mass") @Pattern(regexp = "1-9") @DecimalMin("0") int mass {
return new .....
}
I have a spring boot project where I try to validate that a numeric input is greater than zero. I used @DecimalMin for that but is not working. I stormed the internet and tried different approaches but none seem to work.
This is the code sample:
@GetMapping("/bmi")
public ResponseEntity<BMIDto> getBMI(@RequestParam("mass") @Pattern(regexp = "1-9") @DecimalMin("0") int mass {
return new .....
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要添加
@valid
用于请求正文或字段以验证它。另外,您可以在控制器类中添加@Validated
。You need to add
@Valid
for request body or field to validate it. Also you can add@Validated
in controller class.