【发布时间】:2012-10-08 15:23:08
【问题描述】:
我在 Grails 2.1.0 中使用 CustomDateEditor 时遇到问题
我想要达到的目标:
日期类现在呈现为 08/10/2013 00:00:00 CEST 但我想将格式更改为 08/10/2013(dd/MM/yyyy 格式)
到目前为止我做了什么:
resource.groovy
beans = {
customPropertyEditorRegistrar(myutil.CustomPropertyEditorRegistrar)
}
myutil.CustomPropertyEditorRegistrar
package myutil
import org.springframework.beans.PropertyEditorRegistrar
import org.springframework.beans.PropertyEditorRegistry
import org.springframework.beans.propertyeditors.CustomDateEditor
import java.text.SimpleDateFormat
public class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {
public void registerCustomEditors(PropertyEditorRegistry registry) {
registry.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat('dd/MM/yyyy'), true)) //this doesn't work
registry.registerCustomEditor(java.math.BigDecimal.class, new CurrencyPropertyEditor()) //this work so at least the registerCustomEditors method is invoked
}
}
正如您在我的代码中看到的,有一个 CurrencyPropertyEditor 可以正常工作,所以我在这里很困惑.. 发生了什么?
我四处搜索,似乎我的代码没有错误,但仍然无法正常工作。
提前感谢您的任何提示。
【问题讨论】:
-
嗯.. 不知道,为什么 2 downvote.. 这个问题有那么糟糕吗?
标签: spring date grails grails-2.1