ITeye博客

将字符串的日期转化为Date类型

jhyimu2005 · 2010-07-23 15:04 · java基础 · 企业架构 · Hibernate · Markdown

在Hibernate中有一个非常简单的方法,不再需要你每次都去转换,你只要在你的类中引用了这个函数,它将自动的将需要转换的全部给你转化:


         /**
	 * Defined dateFormat(string to date)
	 * 
	 * @param binder
	 */
	@InitBinder   
	public void initBinder(WebDataBinder binder) {   
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");   
		dateFormat.setLenient(false);     
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));  
	}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。