使用FMT和SpringMVC获取新日期

时间:2012-05-15 10:52:59

标签: spring jsp spring-mvc jstl

我遇到FMT和SpringMVC的问题:

我有一个包含日期字段的对象,所以我使用fmt在我的jsp页面中显示它,如下所示:

<fmt:formatDate value="${form.dtBegin}" type="date" pattern="dd/MM/yyyy HH:mm" />

问题在于,当我提交我的页面时,此字段“form.dtBegin”会获得一个新日期,在我的情况下,此字段不应更改!!

那你对这个问题有什么想法吗?

Thanx all!

1 个答案:

答案 0 :(得分:1)

也许您可以尝试在控制器中绑定日期。

@InitBinder
public void initBinder(WebDataBinder dataBinder) {
    dataBinder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy HH:mm"), true));
}