我不想将它用作POST方法,因为它是一个列表服务,而JSON对象帮助获取过滤器参数。下面是我用POST编写的代码。有没有办法使用GET (遵循Spring-Boot中的REST标准?
TimeEntriesRequest是我的POJO请求类,TimeEntry是我的bean
@RequestMapping(
method=RequestMethod.POST,
value="/TimeEntries",
//consumes = "application/json",
produces = "application/json"
)
@ResponseBody
public List<TimeEntry> getTimeEntries(@RequestBody TimeEntriesRequest timeEntriesRequest) throws RestClientException, IllegalArgumentException, IllegalAccessException {
System.out.println("In controller");
return timeEntriesService.getAllTimeEntries(timeEntriesRequest);
}
发布于 2020-01-23 18:02:30
Spring Boot不支持带有GET方法的@RequestBody
,但您可以尝试使用另一个注释- @RequestParam。
@RequestMapping(
method=RequestMethod.GET,
value="/TimeEntries",
produces = "application/json"
)
@ResponseBody
public List<TimeEntry> getTimeEntries(
@RequestParam(value = "personDTO") String timeEntriesRequestDTO) {
TimeEntriesRequest timeEntriesRequest = new ObjectMapper().readValue(timeEntriesRequestDTO, TimeEntriesRequest.class);
// ...
}
您可以遵循一个tutorial来实现它
附注:我不认为这是一个推荐的方法,因为json会在请求url中,所以在使用这个方法之前,你需要检查是否有其他的方法。
https://stackoverflow.com/questions/59884230
复制相似问题