在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));
}
本文介绍了一个简单的Hibernate技巧,通过在类中引用特定函数自动完成日期格式转换,避免重复工作。该方法使用`SimpleDateFormat`设置特定格式,并通过`CustomDateEditor`注册到`WebDataBinder`,实现对日期字段的自动格式化。
1252

被折叠的 条评论
为什么被折叠?



