下面列出了javax.validation.constraints.DecimalMin#value ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Determine a number type's minimum (inclusive) value.
*
* @param member the field or method to check
* @return specified inclusive minimum value (or null)
* @see Min
* @see DecimalMin
* @see PositiveOrZero
*/
protected BigDecimal resolveNumberInclusiveMinimum(MemberScope<?, ?> member) {
Min minAnnotation = this.getAnnotationFromFieldOrGetter(member, Min.class, Min::groups);
if (minAnnotation != null) {
return new BigDecimal(minAnnotation.value());
}
DecimalMin decimalMinAnnotation = this.getAnnotationFromFieldOrGetter(member, DecimalMin.class, DecimalMin::groups);
if (decimalMinAnnotation != null && decimalMinAnnotation.inclusive()) {
return new BigDecimal(decimalMinAnnotation.value());
}
PositiveOrZero positiveAnnotation = this.getAnnotationFromFieldOrGetter(member, PositiveOrZero.class, PositiveOrZero::groups);
if (positiveAnnotation != null) {
return BigDecimal.ZERO;
}
return null;
}
@Override
public PropertyModel postProcessInternal(PropertyModel propertyModel) {
DecimalMin minAnno = propertyModel.getPropertyItem().getAnnotation(DecimalMin.class);
if (minAnno == null) return propertyModel;
String hint = "";
if (minAnno.inclusive())
hint += " (值大于等于" + minAnno.value() + ")";
else
hint += " (值大于" + minAnno.value() + ")";
propertyModel.setDescription(
TextUtils.combine(propertyModel.getDescription(), hint)
);
return propertyModel;
}
/**
* Determine a number type's minimum (exclusive) value.
*
* @param member the field or method to check
* @return specified exclusive minimum value (or null)
* @see DecimalMin
* @see Positive
*/
protected BigDecimal resolveNumberExclusiveMinimum(MemberScope<?, ?> member) {
DecimalMin decimalMinAnnotation = this.getAnnotationFromFieldOrGetter(member, DecimalMin.class, DecimalMin::groups);
if (decimalMinAnnotation != null && !decimalMinAnnotation.inclusive()) {
return new BigDecimal(decimalMinAnnotation.value());
}
Positive positiveAnnotation = this.getAnnotationFromFieldOrGetter(member, Positive.class, Positive::groups);
if (positiveAnnotation != null) {
return BigDecimal.ZERO;
}
return null;
}
@Override
public void initialize(DecimalMin minValue) {
this.minValue = new BigDecimal(minValue.value() );
this.inclusive = minValue.inclusive();
}