首页 > 其他 > 详细

使用thymeleaf框架,前台日期格式是字符串,后台不能以Date格式接收解决

时间:2017-08-16 12:24:27      阅读:1134      评论:0      收藏:0      [点我收藏+]
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import java.text.SimpleDateFormat;
import java.util.Date;


Spring MVC 框架
公共父类controller类(ParentController )添加以下方法

/**
* 前台日期格式转换为Date格式
* 日期格式:yyyy-MM-dd,第二个参数为是否为空 true代表可以为空
* @param binder
*/
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}

使用thymeleaf框架,前台日期格式是字符串,后台不能以Date格式接收解决

原文:http://www.cnblogs.com/mcybsy/p/7372607.html

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