SpringBoot Hibernate Validation 两个值中必须有一个不为空

说明

提示:本文未经测试,可能好使

有两种解决方法:

@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