zoukankan      html  css  js  c++  java
  • 【spring boot】传递时间类型的字符串,报错:Failed to convert from type [java.lang.String] to type [java.util.Date]

    spring boot 前台GET请求,传递时间类型的字符串,后台无法解析,报错:Failed to convert from type [java.lang.String] to type [java.util.Date]

    而POST请求,传入时间类型字符串,后台是可以解析成Date类型的。

    出现这个错误,在需要接受Date类型的字符串参数的controller层中,加入:

    @InitBinder
        public void initBinder(WebDataBinder binder) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            dateFormat.setLenient(false);
            binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
        }
    

    重启,再次进行访问,即可GET请求传入时间字符串,后台解析为Date类型成功。

    更多:
    https://www.cnblogs.com/sxdcgaq8080/p/10399458.html
    https://blog.csdn.net/gwd1154978352/article/details/75041733

  • 相关阅读:
    Python -- Redis List
    Python --Redis Hash操作
    Python使用redis介绍
    缓存服务器
    linux python3获取ip地址
    Rabbitmq -- rpc
    Rabbitmq--topic
    Rabbitmq -- direct
    删除rabbitmq中持久化的队列和数据
    Exchange-fanout 广播模式
  • 原文地址:https://www.cnblogs.com/DiZhang/p/12544758.html
Copyright © 2011-2022 走看看