SpringBoot Hibernate Validation 两个值中必须有一个不为空 作者:马育民 • 2024-02-21 16:00 • 阅读:10090 # 说明 **提示:**本文未经测试,可能好使 有两种解决方法: - 使用 `@AssertTrue` 注解 - 自定义注解 # @AssertTrue注解解决 ``` public class MyModel { private String value1; private String value2; @AssertTrue(message = "Values are invalid") private boolean isValid() { return value1 != null || value2 != null; } } ``` # 自定义注解解决 https://www.cnblogs.com/itplay/p/15129951.html https://www.jianshu.com/p/4bddeae22f10 # controller 参数注解使用 ``` @PostMapping("/xxx") public Response xxx(@Validated @RequestBody MyModel param) ``` 参考: https://www.cnblogs.com/ShengLiu/p/16581019.html https://blog.csdn.net/TGer_cxy/article/details/118193229 原文出处:http://malaoshi.top/show_1IX7Bw0r9A1v.html