Open houyouliang opened 7 years ago
package com.airport.back.util;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate;
import com.airport.back.vo.ResponseResult; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.hat.vo.ResponseStatistics; import com.hat.vo.SweepInfoReq;
public class RestUtil {
public static ResponseResult post(RestTemplate restTemplate, SweepInfoReq sweepInfoReq) { HttpHeaders headers = new HttpHeaders(); headers.add("channelNo", "XIY"); headers.add("authToken", "CA48FA7B6B50B45BD8B30E53CFB6B9929898647176F1B61C04DCB054BA7C3615"); MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8"); headers.setContentType(type); headers.add("Accept", MediaType.APPLICATION_JSON.toString()); Gson gson = new GsonBuilder().create(); HttpEntity<String> formEntity = new HttpEntity<String>(gson.toJson(sweepInfoReq), headers); ResponseResult result = restTemplate.postForObject("http://localhost:8080/security/find/airportCode", formEntity, ResponseResult.class); return result; } public static ResponseStatistics postStatisstics(RestTemplate restTemplate, SweepInfoReq req) { ResponseStatistics result = null; HttpHeaders headers = new HttpHeaders(); MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8"); headers.setContentType(type); headers.add("Accept", MediaType.APPLICATION_JSON.toString()); Gson gson = new GsonBuilder().create(); HttpEntity<String> formEntity = new HttpEntity<String>(gson.toJson(req), headers); try { result = restTemplate.postForObject("http://localhost:8080/security/statistics/condition", formEntity, ResponseStatistics.class); } catch (Exception e) { result = new ResponseStatistics(); result.setResultCode(StatusCodeUtil.FALL_CODE); result.setResultMsg("接口查询失败!"); } return result; }
}
package com.airport.back.util;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate;
import com.airport.back.vo.ResponseResult; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.hat.vo.ResponseStatistics; import com.hat.vo.SweepInfoReq;
public class RestUtil {
}