Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
joda时间的Spring@InitBinder_Spring_Spring Mvc_Jodatime - Fatal编程技术网

joda时间的Spring@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

我有一个用于java.util.Date的initbinder:

@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。