java - 获取http 400错误请求spring mvc
问题描述
我正在开发 Spring mvc 项目。
我必须实现rest api,我现在正在实现的一个api返回http 400错误请求。在其中获取方法请求。另一个 api 为相同的 json 正常工作,但这个 api 返回 HTTP 400
控制器功能
@RequestMapping(value = "/getSlotsByDateRange/hosid/{hos_id}/from/{start_date}/to/{end_date}" , method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<SlotByDateRange> getSlotsByDateRange(@PathVariable String hos_id,@PathVariable String start_date,@PathVariable String end_date) {
return new ResponseEntity<SlotByDateRange>(hospitalService.getSlotsByDateRange(hos_id,start_date,end_date),HttpStatus.ACCEPTED);
}
请求网址:
getSlotsByDateRange/hosid/0009/from/2021-04-15/to/2021-04-22
解决方案
我刚刚实现了它,它对我有用。
@GetMapping(value = "/getSlotsByDateRange/hosid/{hos_id}/from/{start_date}/to/{end_date}" , produces = "application/json")
对于获取请求,您可以使用@GetMapping 而不是@RequestMapping。由于@GetMapping 本身包含
@RequestMapping(
method = {RequestMethod.GET}
)
希望这对其他人也有帮助。
推荐阅读
- ios - BLE 数据传输是否需要配对(无配对 bt 数据传输)
- ios - 在 Swift 中,在执行 UI 警报之前执行警报关闭中的命令?
- rust - 为什么 Rust 在产生线程时强制在 i32 的情况下使用 move?
- android-studio - 为什么我的第一个颤振项目中出现“UnknownHostException”?
- javascript - 如何正确使用 Axios async/await 使变量失去响应?
- python-3.x - Scrapy.selector 不导入 HtmlXPathSelector
- javascript - Kotlin Multiplatform:将 Kotlin 编译为 JS,然后使用 JS 方法
- javascript - Jq Bootstrap 多选 - 必须至少选择一个值
- python - Django API 抛出错误 r("Expecting value", s, err.value)
- php - DomPDF 计算每个div的高度,防止出现多页