我们从前台想后天传入日期的 时候会发现报了一个天大的错,那是因为spring并没有帮我们自行转换日期格式,为了方便开发只能配置一个全局日期转换器 这样就方便了
下面我们就来看下如何配置
1.在我们项目中建立一个包 我通常是建立web包的 在包里面建立DateEnride.java
package com.newfail.core.web;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.support.WebBindingInitializer;
import org.springframework.web.context.request.WebRequest;
public class DateEnride implements WebBindingInitializer {
public void initBinder(WebDataBinder binder, WebRequest request) {
//日期转换器
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");