首页 > 编程语言 > 详细

SpringMvc接收日期参数

时间:2020-04-23 13:35:27      阅读:58      评论:0      收藏:0      [点我收藏+]

1.Controller方法通过@DateTimeFormat注解来接收参数

@RequestParam("startTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime

 2.设置InitBinder接收参数1

    @InitBinderpublic void initBinderQuery(WebDataBinder binder) {
        binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true));
    }

3.设置InitBinder接收参数2

传入值?query.startTime=2020-04-23

    @InitBinder("query")
    public void initBinderQuery(WebDataBinder binder) {
        binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true));
        binder.setFieldDefaultPrefix("query.");
    }

4. 在参数接收实体上注解

 直接在属性上加@DateTimeFormat注解,就可以进行转化日期格式

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date creatDate ;

    public Date getCreatDate() {
        return creatDate;
    }

    public void setCreatDate(Date creatDate) {
        this.creatDate = creatDate;
    }

 

.

 

SpringMvc接收日期参数

原文:https://www.cnblogs.com/zsg88/p/12759893.html

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