【发布时间】:2018-02-28 11:17:34
【问题描述】:
首先,对不起我的英语,它不是我的主要语言,我不确定这个问题是否完全可以理解。
在收到一个 Map 作为 Rest Web Service 的 @RequestParam 后,我需要做一些查询。
我正在尝试使用 Postman 调用 Web 服务,这是完整的 POST 请求 http://localhost:8080/CDRestApi/rest/cd/esibizione/getIdUdFromIstanzaMetadatoByMap/5/map?25=ALAN&26=IANESELLI
这是我的 WS 代码:
@RequestMapping(value = { "/getIdUdFromIstanzaMetadatoByMap/{id}/map" }, method = RequestMethod.POST, produces = {
MediaType.APPLICATION_JSON_VALUE })
@ResponseBody
public String selectIstanzaMetadato(@PathVariable Long id,
@RequestParam (value="map", required=true) Map<Integer,String> mapQuery) {
Integer key = 25;
System.out.println(mapQuery.get(key));
return mapQuery.get(key).toString();
}
这是邮递员的回答:
{
"timestamp": 1505834218902,
"status": 500,
"error": "Internal Server Error",
"exception": "java.lang.NullPointerException",
"message": "No message available",
"path": "/CDRestApi/rest/cd/esibizione/getIdUdFromIstanzaMetadatoByMap/5/map"
}
System.out 打印是:
17:16:58,891 INFO [stdout] (default task-4) null
我认为 mapQuery 对象没有任何价值,因为它没有正确估价
我已经看过这些帖子,但它们对我没有用: Map<String, String> as @RequestParam in Spring MVC 和 Spring MVC + RequestParam as Map + get URL array parameters not working
我是否错过了正确的 Postman POST 请求?还是网络服务本身的问题?
【问题讨论】:
-
你遇到了什么错误?
-
我会补充问题
-
如果您使用
Map<String, String>和String key = "25";而不是Integer key = 25;是否有效? -
不,它返回相同的错误
-
我还尝试将地图 K/V 作为 json 传递到“原始”邮递员选项卡中,而不是如上所述。但是我收到了错误的请求消息