我正在尝试使用RestTemplate
将pojo发布到rest端点Dto dto = new Dto();
dto.setPhone("12313");
RestTemplate restTemplate = new RestTemplate();
restTemplate.postForObject(new URI("http://localhost:8080/test"), dto, Dto.class);
但我在服务器端收到空dto
@RequestMapping(value = "/test")
@ResponseBody
public DTO test123(DTO dto) {
System.out.println(dto.getPhone()); // empty
return dto;
}
Dto是简单的pojo
public class Dto {
private String phone;
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
答案 0 :(得分:0)
尝试将@RequestBody注释添加到test123方法中:
public DTO test123(@RequestBody DTO dto) {
System.out.println(dto.getPhone()); // empty
return dto;
}