【发布时间】:2018-06-05 12:01:56
【问题描述】:
这个控制器
@GetMapping("temp")
public String temp(@RequestParam(value = "foo") int foo,
@RequestParam(value = "bar") Map<String, String> bar) {
return "Hello";
}
产生以下错误:
{
"exception": "org.springframework.web.method.annotation.MethodArgumentConversionNotSupportedException",
"message": "Failed to convert value of type 'java.lang.String' to required type 'java.util.Map'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.util.Map': no matching editors or conversion strategy found"
}
我想要传递一些带有bar 参数的JSON:
http://localhost:8089/temp?foo=7&bar=%7B%22a%22%3A%22b%22%7D,其中foo 是7,bar 是{"a":"b"}
为什么 Spring 不能进行这种简单的转换?请注意,如果将地图用作@RequestBody 的POST 请求,它会起作用。
【问题讨论】:
-
输入是什么?我敢打赌,您的查询不是有效的 json。
-
localhost:8089/temp?blah=%7B%22a%22%20%3A%20%22b%22%7D 我想通过 {"a" : "b"}
标签: spring spring-boot spring-restcontroller http-request-parameters