一尘不染

Spring MVC日期格式,形式:input

spring

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


阅读 398

收藏
2020-04-20

共1个答案

一尘不染

可以使用fmt:formatDate jstl标签:

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