我想从我的REST API控制器中调用REST API控制器。
“ http:// localhost:8080 / function / 1?filter = {” id“:1435263}”
由于spring mvc无法读取“ {”,因此我们无法直接发送({“ id”:1435263})JSON查询字符串以及url,因此我以map的形式发送查询字符串(搜索变量)。
Object response = restTemplate.getForObject(crudControllerURL,
Object.class, map);
其中map包含值。
在服务器端,我无法检索此地图。我尝试了@RequestParam Object obj,但是没有用。我一无所知,我怎么能在那里得到这些价值?
我需要将其转换为POST吗?
编辑
当我尝试对查询字符串使用整个URL时,我收到了
java.lang.IllegalArgumentException: Not enough variable values available to expand '"id"'
添加服务器端控制器代码片段(不完整),请注意,我需要在Server REST API Controller中访问映射。服务器端控制器
@RequestMapping(value = "/{function}/{type}", method = RequestMethod.GET)
public List<Order> performFetchAll(@PathVariable String function,
HttpServletRequest request) throws JsonParseException,
JsonMappingException, IOException, InvalidAttributesException {
String requestQueryString = request.getQueryString();
if (requestQueryString == null
|| requestQueryString.equalsIgnoreCase(""))
return orderService.findAll();
请提供您的反馈。谢谢。
您可能应该这样做而不是使请求复杂化:
可以这样更改URL:http:// localhost:8080 / function / 1?idFilter = 1435263
@RequestMapping(value = "/{function}/{type}", method = RequestMethod.GET)
public List<Order> performFetchAll(@PathVariable String function, @RequestParam("idFilter") String id, HttpServletRequest request) throws JsonParseException,
JsonMappingException, IOException, InvalidAttributesException {
//DO something
}
如果您的过滤器请求像json一样大而复杂,请将您的方法更改为POST并采用JSON并执行您的逻辑。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句