R
R
Rocket-API
Search…
参数验证,断言判断
1
//正则断言
2
Assert.regex("^\\d+quot;,phone,"非手机号");
3
4
//逻辑断言
5
Assert.isTrue(true,"逻辑不匹配")
6
7
//非空断言
8
Assert.isNotEmpty(name,"参数为空")
9
10
//为空断言
11
Assert.isEmpty("","参数非空")
12
13
//匹配断言
14
Assert.equals("a","a","参数不足")
Copied!
默认抛出RuntimeException.class异常 DefaultAssertException.class 自定义异常通过实现接口: com.github.alenfive.rocketapi.extend.IAssertException
1
@Component
2
public class DefaultAssertException implements IAssertException {
3
4
@Override
5
public void exception(String... input) {
6
if (input.length != 1){
7
throw new RuntimeException("Parameter length mismatch" + input.toString());
8
}
9
throw new RuntimeException(input[0]);
10
}
11
}
Copied!
Last modified 1yr ago
Copy link