ConsumerDeptController.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package cn.hhj.controller;
  2. import cn.hhj.vo.Dept;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.http.HttpEntity;
  5. import org.springframework.http.HttpHeaders;
  6. import org.springframework.http.HttpMethod;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RestController;
  9. import org.springframework.web.client.RestTemplate;
  10. import java.util.List;
  11. @RestController
  12. public class ConsumerDeptController {
  13. private static final String DEPT_GET_URL = "http://MICROCLOUD-PROVIDER-DEPT/dept/get/";
  14. private static final String DEPT_LIST_URL = "http://MICROCLOUD-PROVIDER-DEPT/dept/list/";
  15. private static final String DEPT_ADD_URL = "http://MICROCLOUD-PROVIDER-DEPT/dept/add/";
  16. @Autowired
  17. private RestTemplate restTemplate;
  18. @Autowired
  19. private HttpHeaders headers;
  20. @RequestMapping(value = "/consumer/dept/get")
  21. public Object getDept(long id) {
  22. return this.restTemplate.exchange(DEPT_GET_URL + id,
  23. HttpMethod.GET, new HttpEntity<Object>(this.headers), Dept.class).getBody();
  24. }
  25. @RequestMapping(value = "/consumer/dept/list")
  26. public Object listDept() {
  27. return this.restTemplate.exchange(DEPT_LIST_URL,
  28. HttpMethod.GET, new HttpEntity<Object>(this.headers), List.class).getBody();
  29. }
  30. @RequestMapping(value = "/consumer/dept/add")
  31. public Object addDept(Dept dept) {
  32. return this.restTemplate.exchange(DEPT_ADD_URL, HttpMethod.POST,
  33. new HttpEntity<Object>(dept, this.headers), Boolean.class).getBody();
  34. }
  35. }