需求一:根据id,远程调用接口,返回集合
接口提供方
package com.ruoyi.controller.common; import com.hidata.devops.selfops.domain.OpsResourceList; import com.hidata.devops.selfops.service.IOpsResourceListService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.hidata.devops.selfops.service.IOpsHijobInfoService; import java.util.ArrayList; import java.util.List; import java.util.Map; @RestController @RequestMapping("/hiapi") public class HiApiContoller { @Autowired private IOpsHijobInfoService opsHijobInfoService; /** * 根据nodeId获取ip列表 * @param nodeId * @return */ @RequestMapping("/ip/list") public Object getIpListByNodeId(@RequestBody String nodeId){ return opsResourceListService.getIpListByNodeId(nodeId); } }
接口调用方
String nodeId = "112"; String url = "http://localhost:8180/hiapi/ip/list"; ResponseEntity<List> responseEntity = null; try { responseEntity = restTemplate.postForEntity(url, nodeId, List.class); } catch (RestClientException e) { XxlJobHelper.log(e); } return responseEntity.getBody();
如果要返回对象,那么直接把ResponseEntity 改成 ResponseEntity即可