今天使用element-ui组件的el-date-picker,提交el-form 到后台,然后时间选项是这样的

后台接收是这样的:

 

但是提交后提示,我时间格式不对  Cannot deserialize value of type `java.util.Date` from String 。。。

百度后解决办法:

新增一个配置类,返回类型为MappingJackson2HttpMessageConverter的bean

 

  1.  
     
  2.  
    import java.util.ArrayList;
  3.  
    import java.util.List;
  4.  
     
  5.  
    import org.springframework.context.annotation.Bean;
  6.  
    import org.springframework.context.annotation.Configuration;
  7.  
    import org.springframework.http.MediaType;
  8.  
    import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
  9.  
     
  10.  
    import com.fasterxml.jackson.databind.ObjectMapper;
  11.  
     
  12.  
    @Configuration
  13.  
    public class WebConfig {
  14.  
     
  15.  
    @Bean
  16.  
    public MappingJackson2HttpMessageConverter getMappingJackson2HttpMessageConverter() {
  17.  
    MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
  18.  
    //设置日期格式
  19.  
    ObjectMapper objectMapper = new ObjectMapper();
  20.  
     
  21.  
    mappingJackson2HttpMessageConverter.setObjectMapper(objectMapper);
  22.  
    //设置中文编码格式
  23.  
    List<MediaType> list = new ArrayList<MediaType>();
  24.  
    list.add(MediaType.APPLICATION_JSON_UTF8);
  25.  
    mappingJackson2HttpMessageConverter.setSupportedMediaTypes(list);
  26.  
    return mappingJackson2HttpMessageConverter;
  27.  
    }
  28.  
     
  29.  
    }

问题解决