【发布时间】:2014-05-27 09:29:38
【问题描述】:
以下 URL 导致“400 错误请求”:
http://localhost:8080/springdata_web/rest/errors/test?from=2014-05-25T00:00:00.000Z&to=2014-05-27T00:00:00.000Z
匹配的@RequestMapping 如下。我可以看到我肯定会使用这种方法,因为我在控制台中看到了 Sysout 行,例如使用以下 URL:
http://localhost:8080/springdata_web/rest/errors/test?from=&to=
所以我想这与 Date 类型和 Spring 不接受我在请求参数中传递的格式有关,但我不明白为什么。
@RequestMapping(value = "/test",
method = RequestMethod.GET,
produces = "application/json")
@ResponseBody
public Resource<List<ErrorsDTOEntity>> getAllErrors(
@RequestParam(value = "from", required = true) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date from,
@RequestParam(value = "to", required = true) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date to) {
System.out.println("getAllErrors(Date, Date);");
List<ErrorsDTOEntity> services = errorsDAO.getAllErrors(from, to);
Resource<List<ErrorsDTOEntity>> toReturn = new Resource<List<ErrorsDTOEntity>>(services);
toReturn.add(linkTo(methodOn(ErrorsController.class).getAllErrors(from, to)).withSelfRel());
return toReturn;
}
【问题讨论】:
标签: spring datetime spring-mvc iso