From 429c62013d12dd71d0542ced3a69c47d68c5466a Mon Sep 17 00:00:00 2001 From: whyclxw <810412026@qq.com> Date: 星期三, 04 九月 2024 11:31:12 +0800 Subject: [PATCH] tb_a200_realstate/tb_actm_realstate添加平均单体电压/温度,单体温度平均值 --- src/main/java/com/whyc/util/TestparamHttpUtil.java | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/whyc/util/TestparamHttpUtil.java b/src/main/java/com/whyc/util/TestparamHttpUtil.java index 9c2e880..af641df 100644 --- a/src/main/java/com/whyc/util/TestparamHttpUtil.java +++ b/src/main/java/com/whyc/util/TestparamHttpUtil.java @@ -1,23 +1,61 @@ package com.whyc.util; import com.whyc.dto.ResultA200Dto; +import com.whyc.dto.ResultActmDto; import org.springframework.http.*; import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; public class TestparamHttpUtil { + //post璇锋眰浼犲叆form-data 鏍煎紡 - public static Object postforform_data( RestTemplate restTemplate,String url, MultiValueMap<String, Object> paramMap){ + public static Object postforform_dataA200( RestTemplate restTemplate,String url, MultiValueMap<String, Object> paramMap){ HttpHeaders headers = new HttpHeaders(); HttpMethod method = HttpMethod.POST; // 璁剧疆浠ヨ〃鍗曠殑鏂瑰紡鎻愪氦 headers.add("Content-Type", MediaType.MULTIPART_FORM_DATA_VALUE); HttpEntity< MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(paramMap, headers); - ResponseEntity<String> response = restTemplate.exchange(url, method, requestEntity,String.class ); - String results= response.getBody(); + String results= null; + try { + ResponseEntity<String> response = restTemplate.exchange(url, method, requestEntity,String.class ); + results = response.getBody(); + } catch (RestClientException e) { + results=" {\n" + + " \"code\": \"210\",\n" + + " \"msg\": \"failed in setting test parameters\",\n" + + " \"data\": null,\n" + + " \"count\": 0\n" + + " }"; + } Object dto= ActionUtil.getGson().fromJson(results, ResultA200Dto.class); return dto; } + + //post璇锋眰浼犲叆form-data 鏍煎紡 + public static Object postforform_dataActm( RestTemplate restTemplate,String url, MultiValueMap<String, Object> paramMap){ + HttpHeaders headers = new HttpHeaders(); + HttpMethod method = HttpMethod.POST; + // 璁剧疆浠ヨ〃鍗曠殑鏂瑰紡鎻愪氦 + headers.add("Content-Type", MediaType.MULTIPART_FORM_DATA_VALUE); + HttpEntity< MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(paramMap, headers); + String results= null; + try { + ResponseEntity<String> response = restTemplate.exchange(url, method, requestEntity,String.class ); + results = response.getBody(); + } catch (RestClientException e) { + results=" {\n" + + " \"code\": \"210\",\n" + + " \"msg\": \"failed in setting test parameters\",\n" + + " \"data\": null,\n" + + " \"count\": 0\n" + + " }"; + } + Object dto= ActionUtil.getGson().fromJson(results, ResultActmDto.class); + return dto; + } + + } \ No newline at end of file -- Gitblit v1.9.1