接收Date类型参数BadRequest

使用spring @RestController @RequestMapping接收Date格式参数报错

接收格式为yyyy-MM-dd HH:mm:ss时,在实体类对应字段上添加注解

@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")

如果解决不了问题,可以在controller层创建父类,其中添加代码

    @InitBinder
    public void initBinder(ServletRequestDataBinder bin) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        CustomDateEditor cust = new CustomDateEditor(sdf, true);
        bin.registerCustomEditor(Date.class, cust);
    }

猜你喜欢

转载自blog.csdn.net/MR_L_0927/article/details/83617054