@RestController
@RequestMapping("/t")
public class CallController {
@PostMapping("/e")
public ResponseEntity<Result> call(@RequestParam("id") String id) throws URISyntaxException {
RestTemplate restTemplate = new RestTemplate();
Student student = new Student();
student.setId(id);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("Token", "123456789");
HttpEntity formEntity =
new HttpEntity(student, headers);//此处注意第一个参数设置,如果是对象参数直接填对象参数,否则填map结构参数
URI uploadRoomInfoUrl = new URI("http://127.0.0.1:8081/app1_1/getStuById");
// getForEntity getForObject
// postForEntity postForObject postForLocation
// exchange execute
ResponseEntity<Result> result = restTemplate.postForEntity(
uploadRoomInfoUrl, formEntity, Result.class);
System.out.println(result);
return result;
}
}
Java框架之RestTemplate随笔
最新推荐文章于 2024-03-26 11:33:16 发布