zoukankan      html  css  js  c++  java
  • SpringMvc接收日期参数

    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;
        }

    .

  • 相关阅读:
    作业四 四则运算
    作业三
    作业二(3)
    作业二(2)
    作业二(1)
    作业一
    作业九
    每周更新学习进度表--第十一周
    每周更新学习进度表--第十周
    每周更新学习进度表--第九周
  • 原文地址:https://www.cnblogs.com/zsg88/p/12759893.html
Copyright © 2011-2022 走看看