码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-08-16 12:33:17      阅读:337      评论:0      收藏:0      [点我收藏+]

标签:control   ring   mat   rcu   abi   ati   tab   后台   pre   

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格式接收解决

标签:control   ring   mat   rcu   abi   ati   tab   后台   pre   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!