如何使用Spring boot RestTemplate发布数据

如何使用Spring boot RestTemplate发布数据,spring,rest,spring-boot,swagger,Spring,Rest,Spring Boot,Swagger,实际上,我有一个Rest模板请求: @RequestMapping(value = "/uploadProperties", method = RequestMethod.POST) public @ResponseBody RessourceMetadata uploadProperties( @RequestParam(value = "group", required = true) String group, @RequestParam(value = "

实际上,我有一个Rest模板请求:

@RequestMapping(value = "/uploadProperties", method = RequestMethod.POST)
public @ResponseBody RessourceMetadata uploadProperties(
        @RequestParam(value = "group", required = true) String group,
        @RequestParam(value = "id", required = true) String id,
        @RequestParam(value = "version", required = true) String version,
        @RequestParam(value = "env", required = true) String env) {
    try {
        Ressource ressource = new Ressource(content, group, id, version, env, PropertiesFileUtils.getPropertiesFilename());
        getRessourceService().save(ressource);
        return ressource.getMetadata();
    } catch (RuntimeException e) {
        log.error("Error while uploading.", e);
        throw e;
    } catch (Exception e) {
        log.error("Error while uploading.", e);
        throw new RuntimeException(e);
    }
}
我想添加一个
@RequestBody
,如下所示:

    @RequestBody @RequestParam(value = "content", required = true) ????? content
这个新的
内容
可以包含任何内容


如何正确传递
content
参数?

这样声明一个类

class PostBody{
   Map<String, String> content;
}
{
"content":
    {
      "version" : "1.1",
      "env" : "test"
    }  
}


像这样声明一个类

class PostBody{
   Map<String, String> content;
}
{
"content":
    {
      "version" : "1.1",
      "env" : "test"
    }  
}


你所说的“可以包含任何东西”是什么意思?您想将所有字段(如组、版本、id和环境)封装到内容中,对吗?@pvpkiran no是一个新字段,我可以在其中放置代码或键/值行,例如。。。我不知道是否有可能按照我的要求去做?有些东西要么是
@RequestBody
要么是
@RequestParam
而不是两者都是…你说的“可以包含任何东西”是什么意思?您想将所有字段(如组、版本、id和环境)封装到内容中,对吗?@pvpkiran no是一个新字段,我可以在其中放置代码或键/值行,例如。。。我不知道是否可以按我的要求做?有些东西是
@RequestBody
@RequestParam
不是两者都有…我有这个错误响应体{“timestamp”:1496133459278,“status”:500,“error”:“Internal Server error”,“exception”:“java.lang.IllegalArgumentException”,“message:“'Content-Type'不能包含通配符类型'*'”,“path:“/api/test/uploadProperties”}错误很明显,
Content-Type'不能包含通配符类型'*'
Content-Type中传递的是*。如何调用此rest端点?
curl-X POST--header“Content-Type://*”--header”接受:*/*“-d”{“内容”:{“版本”:“1.1\”,“环境”:“测试”,“id\:“1.1\”}”http://localhost:8080/api/test/uploadProperties?group=a&id=a&version=a&env=a“
两件事。正如@Deinum所说,您正在混合requestparms和requestbody,当您有requestbody时,为什么还要传递请求参数(在“?”之后的url中)。在您的curl中,您的内容类型到底是什么?我有一个错误响应体{“timestamp”:1496133459278,“status”:500,“error”:“Internal Server error”,“exception”:“java.lang.IllegalArgumentException”,“message”:“content-type”不能包含通配符类型“*”,“path”:“/api/test/uploadProperties”}错误很明显,我猜
Content-Type'不能包含通配符类型'*'
您正在传递内容类型中的*。如何调用此rest端点?
curl-X POST--header“Content-Type://*”--header“Accept://*”-d“{\”Content\:{”version\:\:“1.1\”,“env\”:\“测试\”,“id\:\“1.1\”}”http://localhost:8080/api/test/uploadProperties?group=a&id=a&version=a&env=a“
两件事。正如@Deinum所说,您正在混合requestparms和requestbody,当您有requestbody时,为什么还要传递请求参数(在“?”之后的url中)。在你的卷曲中,你的内容类型到底是什么?