gpt4 book ai didi

spring - 实体的 RestTemplate 帖子

转载 作者:IT老高 更新时间:2023-10-28 13:53:51 26 4
gpt4 key购买 nike

我的 post 方法被调用,但我的个人资料为空。这种方法有什么问题?我必须使用 @Requestbody 来使用 RestTemplate 吗?

Profile profile = new Profile();
profile.setEmail(email);
String response = restTemplate.postForObject("http://localhost:8080/user/", profile, String.class);


@RequestMapping(value = "/", method = RequestMethod.POST)
public @ResponseBody
Object postUser(@Valid Profile profile, BindingResult bindingResult, HttpServletResponse response) {

//Profile is null
return profile;
}

最佳答案

您必须以这种方式构建配置文件对象

MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
parts.add("email", email);

Object response = restTemplate.postForObject("http://localhost:8080/user/", parts, String.class);

关于spring - 实体的 RestTemplate 帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12728006/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com