java spring框架,控制层接收日期类型数据,出现403,接收不到等问题

总结的两个日期接收器
一 :前端传字符串类型日期
条件:只会接收到 指定类型 日期yyyy-MM-dd可以按自己想的 写

@InitBinder
protected void initBinder(WebDataBinder binder) {

binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));

}

二:一股脑接收,不能确定到底接收的什么类型日期数据

@InitBinder
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {
    // 处理Date类型
    binder.registerCustomEditor(Date.class, new DateEditor());
    binder.registerCustomEditor(String.class, new StringEditor());
}

如果前段是new Date()传的日期,应该是不需要接收器

猜你喜欢

转载自blog.csdn.net/dd2507935398/article/details/83504999