作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个自定义 toString
我的枚举中的方法:
enum TaxRate implements Serializable {
RATE23(23.0),
...
private String s
private BigDecimal rate
private TaxRate(BigDecimal s) {
this.s = s + "%"
this.rate = s * 0.01
}
public String toString() {
return s
}
<select>
中选择税收时会发生什么?并且发送的值是
23.0%
是 Grails 无法创建/获取
TaxRate
实例...
valueOf(String)
以错误结束..
最佳答案
你看到过 bottom of this page 的条目吗? ?
If you want to use a Enum with a "value" String attribute (a pretty common idiom) in a element, try this:
enum Rating {
G("G"),PG("PG"),PG13("PG-13"),R("R"),NC17("NC-17"),NR("Not Rated")
final String value
Rating(String value) { this.value = value }
String toString() { value }
String getKey() { name() }
}
Then add
optionKey="key"
to your tag.
关于grails - Grails 如何将字符串转换为枚举?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9394517/
我是一名优秀的程序员,十分优秀!