spring mvc date format with form:input [英] spring mvc date format with form:input

查看:134
本文介绍了spring mvc date format with form:input的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有hibernate实体和bean:

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

我还有

@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"

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

When I go to my url I see:

我怎能强迫它有mm / DD / yyyy格式? Thanx

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

推荐答案

解决方案是放入
< mvc:annotation-驱动/>

mvc-dispatcher-servlet.xml
和xmlns:mvc =http://www.springframework.org/schema/ mvc
到xml文件的开头。

The solution is to put
<mvc:annotation-driven/> to mvc-dispatcher-servlet.xml and also xmlns:mvc="http://www.springframework.org/schema/mvc" to the begining of xml file.

这篇关于spring mvc date format with form:input的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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