gpt4 book ai didi

java - 如何使用基于Spring的表单标签日期字段?

转载 作者:行者123 更新时间:2023-12-01 04:45:58 25 4
gpt4 key购买 nike

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

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

在我的演示表单中有字段 private Date fromDate; ,

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

我的问题是他们是否有任何直接标记将日期存储在我的 spring 提供的 jsp 标记中。

否则请给我其他替代方法..

最佳答案

您需要为 Controller 中的日期定义自定义编辑器。请尝试下面的代码。

@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);
}

关于java - 如何使用基于Spring的表单标签日期字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15829893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com