首页 > 编程语言 > 详细

SpringMVC接收String类型时间数值(实体类是Date)转换

时间:2019-12-25 01:17:55      阅读:304      评论:0      收藏:0      [点我收藏+]

SpringMVC接收String类型字符串

bean实体是Date

加入bind

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd‘T‘HH:mm:ss.SSS Z");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));   //true:允许输入空值,false:不能为空值
    }

对单独字符串以及实体类bean接收都起效

SpringMVC接收String类型时间数值(实体类是Date)转换

原文:https://www.cnblogs.com/ukzq/p/12094445.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!