HV000030:找不到类型为:java.math.BigDecimal的验证器

时间:2015-09-03 11:16:56

标签: java bigdecimal spring-mvc-initbinders

我有一个领域:普通     DB:ORDINALITY NOT NULL NUMBER(2)

@Column(name="ORDINALITY")
@NotNull(message="Ordinality is Mandatory")
@Size(max=2,message="Ordinality exceeded the limit, Max. 2 numbers are allowed.")
private BigDecimal ordinality;
  
      
  1. 我想仅限数字输入,确切的注释语法是什么。
  2.   
  3. 当我给出适当的价值并且没有给出任何价值并提交页面时,我收到了以下错误。
  4.   
javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.math.BigDecimal.
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.verifyResolveWasUnique(ConstraintValidatorManager.java:218)
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.findMatchingValidatorClass(ConstraintValidatorManager.java:193)
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.getInitializedValidator(ConstraintValidatorManager.java:97)
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:125)
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:91)
    at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:83)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:547)

1 个答案:

答案 0 :(得分:1)

要设置基础数据库字段的精度,您应该使用@Column注释的精度和比例元素。

@Column(precision=10, scale=2)

要验证号码,请使用@DecimalMax注释。

@DecimalMax("30.00")