gpt4 book ai didi

java - spring mvc 日期格式,格式为 :input

转载 作者:IT老高 更新时间:2023-10-28 13:50:44 25 4
gpt4 key购买 nike

我有 hibernate 实体和一个 bean:

@Entity
public class GeneralObservation {
@DateTimeFormat(pattern = "dd/MM/yyyy")
Date date;

@Column
public Date getDate() {
return date;
}

public void setDate(Date date) {
this.date = date;
}
}

我也有

@InitBinder
protected void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
binder.registerCustomEditor(Date.class, new CustomDateEditor(
dateFormat, false));
}

        form:input
id = "datepicker"
name="date"
itemLabel="date"
path="newObservation.date"

当我转到我的网址时,我看到:

my form

如何强制它具有 mm/DD/yyyy 格式?谢谢

最佳答案

你可以使用 fmt:formatDate jSTL 标签:

<fmt:formatDate value="${yourObject.date}" var="dateString" pattern="dd/MM/yyyy" />
<form:input path="date" value="${dateString} .. />

关于java - spring mvc 日期格式,格式为 :input,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18163404/

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