BigDecimal的JPA @Size注释 [英] JPA @Size annotation for BigDecimal
本文介绍了BigDecimal的JPA @Size注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何为MySQL DECIMAL(x,y)
列使用@Size
注释?
How do I use the @Size
annotation for MySQL DECIMAL(x,y)
columns?
我正在使用BigDecimal
,但是当我尝试包含@Size
max
时,它不起作用.这是我的代码:
I'm using BigDecimal
, but when I try to include the @Size
max
it doesn't work. Here is my code:
@Size(max = 7,2)
@Column(name = "weight")
private BigDecimal weight;
推荐答案
您可以直接使用Hibernate Validator,并使用
You could use the Hibernate Validator directly, and annotate your field with @Digits like so:
@Digits(integer=5, fraction=2)
@Column(name = "weight")
private BigDecimal weight;
这篇关于BigDecimal的JPA @Size注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文