package cn.hhj.controller; import cn.hhj.vo.Dept; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import java.util.List; @RestController public class ConsumerDeptController { private static final String DEPT_GET_URL = "http://MICROCLOUD-PROVIDER-DEPT/dept/get/"; private static final String DEPT_LIST_URL = "http://MICROCLOUD-PROVIDER-DEPT/dept/list/"; private static final String DEPT_ADD_URL = "http://MICROCLOUD-PROVIDER-DEPT/dept/add/"; @Autowired private RestTemplate restTemplate; @Autowired private HttpHeaders headers; @RequestMapping(value = "/consumer/dept/get") public Object getDept(long id) { return this.restTemplate.exchange(DEPT_GET_URL + id, HttpMethod.GET, new HttpEntity(this.headers), Dept.class).getBody(); } @RequestMapping(value = "/consumer/dept/list") public Object listDept() { return this.restTemplate.exchange(DEPT_LIST_URL, HttpMethod.GET, new HttpEntity(this.headers), List.class).getBody(); } @RequestMapping(value = "/consumer/dept/add") public Object addDept(Dept dept) { return this.restTemplate.exchange(DEPT_ADD_URL, HttpMethod.POST, new HttpEntity(dept, this.headers), Boolean.class).getBody(); } }