spring mvc 后台只接收String类型,所以需要对日期类型处理

来源:互联网 发布:网络推广客服专员 编辑:程序博客网 时间:2024/04/27 19:37
一、只需要在方法中加入
    @InitBinder    protected  void initBinder(WebDataBinder binder) {        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));    }

方法就可以

二、注解方式:   

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")  //取日期时使用    @DateTimeFormat(pattern = "yyyy-MM-dd")//存日期时使用    private Date startTime;


1 0