Spring MVC日期格式,形式:input

I have hibernate entity and a 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;

}

}

also I have

@InitBinder

protected void initBinder(WebDataBinder binder) {

SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");

binder.registerCustomEditor(Date.class, new CustomDateEditor(

dateFormat, false));

}

and

        form:input

id = "datepicker"

name="date"

itemLabel="date"

path="newObservation.date"

How can I force it to have mm/DD/yyyy format? Thanx

回答:

可以使用fmt:formatDate jstl标签:

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

<form:input path="date" value="${dateString} .. />

以上是 Spring MVC日期格式,形式:input 的全部内容, 来源链接: utcz.com/qa/405646.html

回到顶部