【问题标题】:I need to pass two @RequestBody parameters into my REST API POST method. How can I achieve this and can I do it using DefaultHttpClient?我需要将两个 @RequestBody 参数传递给我的 REST API POST 方法。我怎样才能做到这一点,我可以使用 DefaultHttpClient 做到这一点吗?
【发布时间】:2018-04-04 02:33:34
【问题描述】:

我的 REST API 方法是:

@RequestMapping(value = "/api/test/summary", method = RequestMethod.POST)
postSummaryData(@RequestBody String one, @RequestBody String two) { ... }

【问题讨论】:

  • class Foo { String one; String two; } 然后postSummaryData(@RequestBody Foo foo)?

标签: spring rest spring-mvc


【解决方案1】:

@RequestMapping(value = "/api/test/summary/{one}/{two}", method = RequestMethod.POST) postSummaryData(@RequestParam String 一,@RequestParam String 二) { }

你也可以试试下面的:

@RequestMapping(value = "/api/test/summary", method = RequestMethod.POST) postSummaryData() {

RequestAttributes attr = RequestContextHolder.getRequestAttributes();

HttpServletRequest 请求 = ((ServletRequestAttributes)attr).getRequest();

// 你可以从这个请求中获取参数

}

【讨论】:

  • 不应该是@PathVariable 而不是@RequestParam
猜你喜欢
  • 2022-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-07
  • 2018-10-05
  • 2015-05-01
  • 1970-01-01
相关资源
最近更新 更多