- springboot不会自动注册RestTemplate,需要自己注册bean
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder){
return builder.build();
}
- 创建测试的controller,创建一个get请求和一个post请求作为演示
@Data
public class User {
private Long id;
private String name;
private Integer age;
}
@RestController
public class TestController {
@GetMapping("getString")
public String getString(String src){
return src;
}
@PostMapping("getUser")
public User getUser(@RequestBody User user){
return user;
}
}