spring - 实体的 RestTemplate 帖子

标签 spring spring-mvc spring-3

我的 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/

相关文章:

java - Spring 4应用程序注册为Eureka客户端

java - 从包含字节数组图像的数据库获取对象

java - 在 Spring 中,@RequestParameter 注释不接受 defaultValue 参数的 boolean 值,它只适用于字符串 URL 请求参数

java - 创建名称为 'hypermediaRepresentionModelProcessorConfigurator' 的 bean 时出错

json - 从 Angular 执行 $http.put 时,Spring MVC @ModelAttribute 数据始终为 null

java - 如何使用带有图 block 的 Spring MVC 避免多个 Controller 将相同类型的数据移交给 View

具有多个登录页面的 Spring 安全性

java - Mockito - 模拟服务时抛出 nullpointerException

spring - 在 3.0.x 版本中禁用 Spring 方法安全性

spring-security - Spring 3 : Can't find AuthenticationProcessingFilter