我需要在我的端点中收到LocalDateTime
或Instant
:
@RequestMapping(
path = Constants.AUDITS_MAPPING,
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE
)
public Collection<Audit> listPendingAudits(Instant /*or LocalDateTime*/ deadline);
有可能吗?有什么解决方法吗?
答案 0 :(得分:4)
您可以使用@RequestParam
批注并将日期值作为查询参数发送。例如:
GET http://localhost:8080/api/resource?date=2018-10-31T01:30:00.000
要在Spring中启用此功能,您必须在参数中添加@DateTimeFormat
批注:
@RequestMapping(
path = Constants.AUDITS_MAPPING,
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE
)
public Collection<Audit> listPendingAudits(@RequestParam(value = "date", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime deadline);