通过邮递员传递日期
Pass date through postman
这是我的控制器:
@GetMapping("/checkMeetingRoomAvailability")
public @ResponseBody ResponseDto checkMeetingRoomAvailability(@DateTimeFormat(pattern = "dd-M-yyyy hh:mm:ss") Date begin,
@DateTimeFormat(pattern = "dd-M-yyyy hh:mm:ss") Date end, @RequestParam Integer capacity) {
return meetingRoomServiceLocal.checkMeetingRoomAvailability(begin, end, capacity);
}
当我使用邮递员传递输入时,它给出了 400 个错误请求。
meetingRoomController/checkMeetingRoomAvailability?begin=30-9-2020 14:30:00&end=30-9-2020 15:30:00&capacity=10
我无法弄清楚为什么会出现此错误。
以下任一解决方案都有效:
- 推荐方案:将代码中的
dd-M-yyyy hh:mm:ss
替换为dd-M-yyyy'T'hh:mm:ss
,然后可以像meetingRoomController/checkMeetingRoomAvailability?begin=30-9-2020T14:30:00&end=30-9-2020T15:30:00&capacity=10
.[=22=一样进行测试]
- 对 URL 进行编码,以便可以对日期和时间之间的 space 进行适当编码,例如作为测试,您可以使用一些编码工具对
meetingRoomController/checkMeetingRoomAvailability?begin=30-9-2020 14:30:00&end=30-9-2020 15:30:00&capacity=10
进行编码,例如https://www.urlencoder.org/ 并在 Postman 中使用编码后的 URL。我不推荐这样做,因为它会强制您的客户编码 URL,然后才能向您的服务器发送请求。
这是我的控制器:
@GetMapping("/checkMeetingRoomAvailability")
public @ResponseBody ResponseDto checkMeetingRoomAvailability(@DateTimeFormat(pattern = "dd-M-yyyy hh:mm:ss") Date begin,
@DateTimeFormat(pattern = "dd-M-yyyy hh:mm:ss") Date end, @RequestParam Integer capacity) {
return meetingRoomServiceLocal.checkMeetingRoomAvailability(begin, end, capacity);
}
当我使用邮递员传递输入时,它给出了 400 个错误请求。
meetingRoomController/checkMeetingRoomAvailability?begin=30-9-2020 14:30:00&end=30-9-2020 15:30:00&capacity=10
我无法弄清楚为什么会出现此错误。
以下任一解决方案都有效:
- 推荐方案:将代码中的
dd-M-yyyy hh:mm:ss
替换为dd-M-yyyy'T'hh:mm:ss
,然后可以像meetingRoomController/checkMeetingRoomAvailability?begin=30-9-2020T14:30:00&end=30-9-2020T15:30:00&capacity=10
.[=22=一样进行测试] - 对 URL 进行编码,以便可以对日期和时间之间的 space 进行适当编码,例如作为测试,您可以使用一些编码工具对
meetingRoomController/checkMeetingRoomAvailability?begin=30-9-2020 14:30:00&end=30-9-2020 15:30:00&capacity=10
进行编码,例如https://www.urlencoder.org/ 并在 Postman 中使用编码后的 URL。我不推荐这样做,因为它会强制您的客户编码 URL,然后才能向您的服务器发送请求。