在Grails中代表Money(价值+货币)的最佳实践 [英] Best practice to represent Money (value + currency) in Grails
问题描述
我对Java货币类型并不熟悉,以及它如何在Grails中使用。尽管我还没有使用它,但我在视图中看到了一个标记< g:currencySelect>
。那么,我该如何在域类中表示它。
class Money {
BigDecimal value
货币币种
....
}
还是有更好的sol,比较差异货币对象,根据区域设置的格式','在欧盟的分隔符等)
在此先感谢。
Babu。
您可能想看一看货币插件。它提供了一个Money类,用于持有不同货币的金额。它们可以像这样嵌入到域类中:
类CustomerTransaction {
Date date = new Date()
金额
static嵌入= ['money']
}
I'm not much familiar to Java Currency type, and how it being used in Grails. Though, I'm yet to use it, I saw a tag <g:currencySelect>
to use in the views. So, how do I represent it in the domain class.
class Money {
BigDecimal value
Currency currency
....
}
or is there a better sol, which compares diff money objects, format according to the locale ( ',' in EU for separator etc)
thanks in advance. Babu.
You might want to take a look a the Currencies plugin. It provides a Money class for holding monetary amounts of differing currencies. They can be embedded into domain classes like so:
class CustomerTransaction {
Date date = new Date()
Money amount
static embedded = ['money']
}
这篇关于在Grails中代表Money(价值+货币)的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!