获取java.util.Date时,Spring@RequestParam vs@ModelArribute

获取java.util.Date时,Spring@RequestParam vs@ModelArribute,java,spring-mvc,web-applications,Java,Spring Mvc,Web Applications,我遇到的情况是,以下代码正确地获取了日期,而没有时间: @RequestMapping(value="/pdf", method={RequestMethod.GET,RequestMethod.POST}) public void printPdf(@RequestParam("printDateTime") Date printDateTime .... more) { printDateTime; // contains date, but NOT the time ..

我遇到的情况是,以下代码正确地获取了日期,而没有时间:

@RequestMapping(value="/pdf", method={RequestMethod.GET,RequestMethod.POST})
public void printPdf(@RequestParam("printDateTime") Date printDateTime  .... more) {
    printDateTime; // contains date, but NOT the time
    ...more code here...
}
但是,当我使用modelAttribute时,它将正确地从客户端获取日期和时间

@RequestMapping(value="/pdf", method={RequestMethod.GET,RequestMethod.POST})
public void printPdf(@ModelAttribute WorkerSearchParamsDto searchParamsDto  .... more) {

   searchParamsDto.getPrintDateTime(); // Returns correct date with client time...
   ...more code here...
}
我有点困惑,为什么会是这样,我能做些什么来解决这个问题。我们不希望在打印日期中使用modelAttribute,这是有原因的,因为我们可以解决这个问题。任何想法都会有帮助

明确地说,我们想要的是时间,而不仅仅是日期


我们正在运行Spring 3.2.4.RELEASE

除了第一个片段的注释日期和第二个片段的WorkersSearchParamsTo之外,代码中还有一个差异。您是否尝试对这两种方法都使用Date?WorkerSearchParamsTo包含哪些内容?@AlexeyMalev最初只尝试使用RequestParam方法。当我将日期值添加到DTO时,它开始正确获取时间。来自客户端的值在这两种情况下都是相同的。@RaulRene WorkersearchParamsTo只是一个POJO、直接的getter和setter。我认为差异一定在于HandlerMethodArgumentResolver解析参数值的方式,因为两个参数都由不同的解析程序支持。