如何在 @Entity class 中获取 BigDecimal 类型数据的精度

How to get precision of BigDecimal type data in an @Entity class

我有一个@Entity class,其中有一个像这样的实例

@Column(name="some_column_in_table", precision=3, scale=1)
    private BigDecimal someColumnInTable;

如何获得该实例的精度?

我不太确定我是否正确解决了你的问题,但你试过了吗

 someColumnInTable.precision()

如 BigDecimal JavaDoc 所述?

http://docs.oracle.com/javaee/5/api/javax/persistence/Column.html 如果您只想以编程方式获取注释中设置的值,您可以这样做。 Column 的保留设置为 RUNTIME,因此可以使用 Reflection。

Field f = MyClass.class.getDeclaredField("someColumnInTable")) { 
Column column = f.getAnnotation(Column.class);
if (column != null){
   System.out.println(column.precision());
}

以下是一些其他示例: Is it possible to read the value of a annotation in java?