我想将某些字段视为可选字段,如果值为 null 或空白,则不要检查其他带注释的约束。有一些方法可以实现它!阅读此步骤Java bean 验证:仅当属性不为空时才强制执行 @Pattern似乎不能满足我的需求。下面举个例子来解释我的意思:
public class Test {
@Max(value=100) <--mandatory
private int parA;
@Optional <-Custom annotation telling "do not check other if null or blank"
@Range(min=10, max=200)
private int parB;
...
Run Code Online (Sandbox Code Playgroud)
}
我需要在运行时检查服务器是否在http://localhost 中运行 在 网上搜索我还没有找到任何好的解决方案。一些忠告?
谢谢