在Grails中代表Money(价值+货币)的最佳实践 [英] Best practice to represent Money (value + currency) in Grails

查看:104
本文介绍了在Grails中代表Money(价值+货币)的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆