spring MVC Could not instantiate bean class [java.util.Date]: Constructor threw exception; nested ex

Could not instantiate bean class [java.util.Date]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException

 

Spring MVC 时间参数没有转化的原因

参考 https://blog.csdn.net/wwrzyy/article/details/79690601

console报错是这样,但是页面报错400,请求错误,但是还会报一些奇怪的错误令人费解:
Uncaught SyntaxError: Unexpected token <很具有迷惑性。
这里其实是springmvc在进行对象封装的时候对时间字段需要我们自己在controller层进行格式化,下面将这段代码添加到controller层就好
 

/**
     * 数据初始化绑定:SpringMVC中,数据从前台过来会将字符串转换为日期对象
     * @param binder
     */
     @InitBinder
     public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");//格式根据个人需求进行设定
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));   //true:允许输入空值,日期可以为空,false:不能为空值
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值