2016-12-19 24 views
0

有沒有辦法來格式化的:如何格式化與標準(JPA 2.0的EclipseLink)數爲貨幣

CriteriaQuery<Country> q = cb.createQuery(Country.class); 
    Root<Country> c = q.from(Country.class); 
    q.select(c.get("currency")).distinct(true); 

所以,當返回中所有數字的貨幣因素,他們看起來像:

12345 - > $ 12,345.00

123,45 - > $; 123.45&

這樣,我不腦水腫循環的結果集格式化字符串。

+0

https://stackoverflow.com/questions/2379221/java-currency-number-format#2379425 –

+0

我應該在哪裏放置NumberFormatter? –

+0

我知道如何格式化Java數字,但我不知道如何使用Criteria執行此操作。 –

回答

0

這裏的答案:

https://stackoverflow.com/a/40008789/2545722

只需要使用CriteriaBuilder函數方法,它允許開發者調用SQL函數。我不喜歡它,因爲如果數據庫被更改,這個代碼應該改變。