2011-11-02 53 views
0

我在Sql server表中有一个Money字段,并且在休眠时映射为double。 ? 如何为999,999格式化(三要三分开)在休眠中格式化列

例如:45000.0 ---> 45000

+1

数据库和休眠保存数据,而不是格式化它。应用程序的视图部分应该回答用于从数据库中选择使用hibernate选择的数据的格式。 – svaor

回答

0
public class MyClass { 
    BigDecimal money; 
    public static final NumberFormat NUMBER_FORMAT = new DecimalFormat(",###"); 

    @Column 
    public BigDecimal getMoney() { 
     return money; 
    } 

    @Transient 
    public String displayMoney(){ 
     return NUMBER_FORMAT.format(money); 
    } 

}