我有一个@Entity类,其中有这样一个实例如何获得的BigDecimal类型数据的精度在@Entity类
@Column(name="some_column_in_table", precision=3, scale=1)
private BigDecimal someColumnInTable;
我怎样才能获得该实例的精度?
我有一个@Entity类,其中有这样一个实例如何获得的BigDecimal类型数据的精度在@Entity类
@Column(name="some_column_in_table", precision=3, scale=1)
private BigDecimal someColumnInTable;
我怎样才能获得该实例的精度?
http://docs.oracle.com/javaee/5/api/javax/persistence/Column.html 如果您只是想以编程方式获取注释中设置的值,您可以这样做。列的保留设置为RUNTIME,因此使用反射是可能的。
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?
你能解释一下你到底想要什么? 注解状态,DB中列的精度是多少。你想要BigDecimal精度的实例吗? – maslan 2015-01-21 09:59:52
是的annotatio说它的精度是3,但我怎样才能检查这与代码? – Varun 2015-01-21 10:09:40
你可以在我的答案下面找到它 - 使用反射 – maslan 2015-01-21 10:10:27