2017-09-28 106 views
0

我有以下的模型類Bean驗證更新消息與錯誤

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

我怎麼會去驗證的範圍大小,這些領域? 我曾嘗試加入

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; 

}

,但我想知道是否有辦法在驗證失敗的消息,其startnum和endnum甚至什麼設定maxrangesize顯示,所以錯誤會對用戶有用嗎?

回答

0

嘗試這個例子:

@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; 
+0

嗨,我不知道這是怎麼尋找兩個int值,因爲這之間的範圍只是在尋找一個有用嗎? – obsessiveCookie