1

在我的 Spring 应用程序中有 jsp 和 form。

demo.jsp 有一个字段<form:input path="fromDate"/>

在我的 DemoForm 中有字段private Date fromDate;

当我们存储值 Null 值存储...

我的问题是他们的任何直接标签,用于将日期存储在我的 spring 提供的 jsp 标签中。

其他明智的给我其他替代方式..

4

1 回答 1

0

您需要在控制器中为 Date 定义自定义编辑器。请尝试以下代码。

@InitBinder
public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {
    DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
    df.setLenient(false);
    CustomDateEditor editor = new CustomDateEditor(df, true); // second argument 'allowEmpty' is set to true to allow  null/empty values.
    binder.registerCustomEditor(Date.class, editor);
}
于 2013-04-08T14:22:20.943 回答