Ribbon RestTemplate GET 请求

		ResponseEntity responseEntity = restTemplate.getForEntity("http://USER-SERVICE/user?name={1}", String.class,"lgt");
		String body = responseEntity.getBody();

其中{1}为占位符,若希望返回user对象可以这么写

		ResponseEntity responseEntity = restTemplate.getForEntity("http://USER-SERVICE/user?name={1}", String.class,"lgt");
		User body = responseEntity.getBody();

若参数为Map类型则需要放进Map再传

Map params = new HashMap<>(); 
		params.put("name", "lgt");
		ResponseEntity responseEntity = restTemplate.getForEntity("http://USER-SERVICE/user?name={name}", String.class,params);

第二种是getForObject

restTemplate.getForObject(uri, String.class);

restTemplate.getForObject(uri, User.class);

 

你可能感兴趣的:(spring,cloud,Ribbon)