简体   繁体   English

与错误有关的Bean验证更新消息

[英]Bean Validation update message relating to error

I have the following model class 我有以下模型课

 public class ContactDetail {
     @NotNull(message="StartNum cannot be null")
     private int startNum;
     @NotNull(message="EndNum cannot be null")
     private int endNum; }

How would I go about validating the range size for these fields? 我将如何验证这些字段的范围大小? I have tried adding 我尝试添加

public int maxRangeSize=1000;

@AssertTrue(message="Range size is invalid" )
public boolean isRangeValid(){

Integer rangeSize= endNum-startNum;

if(rangeSize < 0 || rangeSize >= maxRangeSize)
{
    return false;
}
return true;

} }

but I would like to know if there is a way to show in the validation failure message which startnum and endnum or even whats the set maxrangesize, so the error will be useful to the user? 但我想知道是否有一种方法可以在验证失败消息中显示哪个startnum和endnum甚至是设置的maxrangesize,因此该错误对用户有用吗?

try this example: 试试这个例子:

@Digits(integer = 3, fraction = 0, message = "The value of age can not be more than 3 digits")
@Range(min = 10, max = 150)
private int age;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM