关于spring @DateTimeFormat的一些混淆 [英] some confusions about spring @DateTimeFormat

查看:172
本文介绍了关于spring @DateTimeFormat的一些混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我在使用@ DateTimeFormat时遇到了一些困惑。我对@DateTimeFormat的理解是用于验证jsp页面中的字符串日期并将其转换为某个实体的字段,其格式由@DateTimeFormate指定(例如:yyyy / MM / dd)。

假设我有一个联系人实体,我收到联系人的信息并在编辑表单中显示,我发现,当我使用

Hi all,I hava some confusions when using @DateTimeFormat.My understanding about @DateTimeFormat is that is's used to validate and convert the string date in the jsp page to the some entity's field whose format is specified by the @DateTimeFormate(eg:yyyy/MM/dd).
Suppose that I hava a contact entity,I get the contact's info and displays it in the edit form,I find that,when I use

<form:input path="birthDate" id="birthDate" />

,其html输出将使用中指定的格式进行格式化@ DateTimeFormat,使用常规方式,例如

,its html output will be formatted using the format specified in the @DateTimeFormat,while using the normal way,such as

<p>${contact.birthDate}</p>

,它只是使用db中的日期直接输出它。

我的问题是:

1.什么是@ DateTimeFormat的效果?它真的不仅可以将字符串日期(在jsp页面中)格式化为实体的字段,还可以从db格式化实体的字段并使用指定的格式在jsp页面中显示它吗?如果是这样,spring如何处理此注释?其他格式化程序注释是否也能正常工作?

2.为什么它只适用于

,it just output it directly using the date from db.
My questions are:
1.What's @DateTimeFormat's effect? Can it really not only format the string date(in jsp page) to the entity's field but also format the entity's field from db and displays it in the jsp page using the specified format?If so,how spring handle this annotation? Does other formatter annotation work so?
2.Why it just work for the

<form>

标签情况?

3.进一步介绍这个将不胜感激。



谢谢。

tag situation?
3.And further introductions about this will be appreciated.

Thanks.

推荐答案

{contact.birthDate} < / p >
{contact.birthDate}</p>

,它只是直接使用db中的日期输出它。

我的问题是:

1.什么是@ DateTimeFormat的效果?它真的不仅可以将字符串日期(在jsp页面中)格式化为实体的字段,还可以从db格式化实体的字段并使用指定的格式在jsp页面中显示它吗?如果是这样,spring如何处理此注释?其他格式化程序注释是否也能正常工作?

2.为什么它只适用于

,it just output it directly using the date from db.
My questions are:
1.What's @DateTimeFormat's effect? Can it really not only format the string date(in jsp page) to the entity's field but also format the entity's field from db and displays it in the jsp page using the specified format?If so,how spring handle this annotation? Does other formatter annotation work so?
2.Why it just work for the

<form>

标签情况?

3.进一步关于这一点的介绍将不胜感激。



谢谢。

tag situation?
3.And further introductions about this will be appreciated.

Thanks.


这篇关于关于spring @DateTimeFormat的一些混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆