我有一个领域:普通 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;
- 我想仅限数字输入,确切的注释语法是什么。
- 当我给出适当的价值并且没有给出任何价值并提交页面时,我收到了以下错误。
醇>
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)
答案 0 :(得分:1)
要设置基础数据库字段的精度,您应该使用@Column
注释的精度和比例元素。
@Column(precision=10, scale=2)
要验证号码,请使用@DecimalMax
注释。
@DecimalMax("30.00")