【发布时间】:2019-07-04 00:22:00
【问题描述】:
我需要查找日期范围之间的条目,并希望在 Spring Boot API 中进行 GET 调用,如下所示,
$ curl -X GET http://localhost:8080/api/v1/appointments/findWithRange?start=2018-10-01&end=2018-10-15
我编写了 GET 调用,
@GetMapping("/findWithRange")
public ResponseEntity<List<Appointment>> findAllWithCreationRange(@RequestParam("start") Date start, @RequestParam("end") Date end) {
List<Appointment> appointments = service.findAllWithCreationRange(start, end);
if (Objects.isNull(appointments)) {
ResponseEntity.badRequest().build();
}
return ResponseEntity.ok(appointments);
}
我得到了返回响应,
{"timestamp":"2019-02-10T07:58:22.151+0000","status":400,"error":"Bad Request","message":"Required Date parameter 'end' is not present","path":"/api/v1/appointments/findWithRange"}
如何正确编写调用?似乎我无法调试,因为断点没有捕获。
【问题讨论】:
-
你确定要从你的 shell 中引用你的
&吗? -
什么意思?
-
在您获得 curl 输出并打印类似
[1] 12345的内容之前,shell 是否会立即返回? -
是的,我只是发现 API 很好,并且在 Chrome 中可以正常工作。问题仅在终端中。
-
你需要了解主题shell quoting,这是你的问题。
标签: java rest spring-boot curl https