joda时间的Spring@InitBinder
我有一个用于java.util.Date的initbinder:joda时间的Spring@InitBinder,spring,spring-mvc,jodatime,Spring,Spring Mvc,Jodatime,我有一个用于java.util.Date的initbinder: @InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat( Constants.DATE_PICTURE); dateFormat.setLenient(false); binder.registerCustomEditor
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat(
Constants.DATE_PICTURE);
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(
dateFormat, true));
可以使用什么绑定joda time LocalDateTime?
当您使用命令对象时,我使用的是Spring3.1,那么一种完全不同、更优雅的方法是可能的:使用注释
public class CommandObject {
@DateTimeFormat(pattern="yyyy/MM/dd hh:mm:ss a")
public Date myDate();
}
@Controller
public class ControllerClass{
@RequestMapping("/myUrl")
public ModelAndView(CommandObject c) {...}
}
(@See了解一些格式化程序示例)不需要命令对象。注释可以以任何可以想到的方式使用;)+1用于没有过时属性编辑器垃圾的解决方案。
@DateTimeFormat
也支持Joda对象,因此+1。