From a088987e7ab7005db1bb1da61dfc0cf420e02d78 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 13 十一月 2024 17:11:28 +0800 Subject: [PATCH] 1 --- src/main/java/com/moon/server/helper/RestHelper.java | 70 +---------------------------------- 1 files changed, 2 insertions(+), 68 deletions(-) diff --git a/src/main/java/com/moon/server/helper/RestHelper.java b/src/main/java/com/moon/server/helper/RestHelper.java index 32828db..1e5e974 100644 --- a/src/main/java/com/moon/server/helper/RestHelper.java +++ b/src/main/java/com/moon/server/helper/RestHelper.java @@ -24,20 +24,12 @@ import java.util.List; import java.util.Map; -/** - * Rest鏈嶅姟甯姪绫� - * @author WWW - */ +@SuppressWarnings("ALL") public class RestHelper { private static RestTemplate restTemplate; private final static Log log = LogFactory.getLog(RestHelper.class); - /** - * 鑾峰彇RestTemplate - * - * @return RestTemplate - */ public static RestTemplate getRestTemplate() { if (restTemplate == null) { restTemplate = SpringContextHelper.getBean(RestTemplate.class); @@ -46,13 +38,6 @@ return restTemplate; } - /** - * Get璇锋眰-HttpURLConnection - * - * @param url URL鍦板潃 - * @return 瀛楃涓� - * @throws IOException IO寮傚父 - */ public static String getForConn(String url) throws IOException { BufferedReader br = null; HttpURLConnection conn = null; @@ -84,14 +69,6 @@ } } - /** - * Post璇锋眰-HttpURLConnection - * - * @param url URL鍦板潃 - * @param query 鏌ヨ鏉′欢 - * @return 瀛楃涓� - * @throws IOException IO寮傚父 - */ public static String postForConn(String url, String query) throws IOException { BufferedReader br = null; HttpURLConnection conn = null; @@ -100,7 +77,6 @@ URL restUrl = new URL(url); conn = (HttpURLConnection) restUrl.openConnection(); - // POST,GET,PUT,DELETE conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setDoOutput(true); @@ -132,12 +108,6 @@ } } - /** - * Get璇锋眰-CloseableHttpClient - * - * @param uri Uri鍦板潃 - * @return 鍝嶅簲瀛楃涓� - */ public static String get(String uri) { try { CloseableHttpClient httpClient = HttpClients.custom().build(); @@ -145,7 +115,7 @@ HttpGet httpGet = new HttpGet(uri); CloseableHttpResponse closeResponse = httpClient.execute(httpGet); - // 鍙栧嚭杩斿洖浣� + HttpEntity entity = closeResponse.getEntity(); return EntityUtils.toString(entity, StaticData.TEXT_ENCODER); @@ -156,13 +126,6 @@ } } - /** - * Post璇锋眰-CloseableHttpClient - * - * @param uri Uri鍦板潃 - * @param postData 寰呭彂閫佹暟鎹� - * @return 鍝嶅簲瀛楃涓� - */ public static String post(String uri, List<NameValuePair> postData) { try { CloseableHttpClient httpClient = HttpClients.custom().build(); @@ -173,7 +136,6 @@ CloseableHttpResponse closeResponse = httpClient.execute(httpPost); - // 鍙栧嚭杩斿洖浣� HttpEntity entity = closeResponse.getEntity(); return EntityUtils.toString(entity, StaticData.TEXT_ENCODER); @@ -184,13 +146,6 @@ } } - /** - * 鑾峰彇閿欒淇℃伅 - * - * @param uri Uri鍦板潃 - * @param ex 寮傚父 - * @return 閿欒淇℃伅 - */ public static String getErrorInfo(String uri, Exception ex) { Map<String, Object> map = new LinkedHashMap<>(); map.put("result", null); @@ -202,63 +157,42 @@ return map.toString(); } - /** - * GET璇锋眰锛圧EST锛� - */ public static String getForRest(String uri) { RestTemplate rest = getRestTemplate(); return rest.getForObject(uri, String.class); } - /** - * GET璇锋眰锛圧EST锛� - */ public static <T> T getForRest(String uri, Class<T> clazz) { RestTemplate rest = getRestTemplate(); return rest.getForObject(uri, clazz); } - /** - * POST璇锋眰锛圧EST锛� - */ public static String postForRest(String uri, Map<String, Object> map) { RestTemplate rest = getRestTemplate(); return rest.postForObject(uri, map, String.class); } - /** - * POST璇锋眰锛圧EST锛� - */ public static <T> String postForRest(String uri, List<T> list) { RestTemplate rest = getRestTemplate(); return rest.postForObject(uri, list, String.class); } - /** - * POST璇锋眰锛圧EST锛� - */ public static <T> String postForRest(String uri, T t) { RestTemplate rest = getRestTemplate(); return rest.postForObject(uri, t, String.class); } - /** - * DELETE璇锋眰锛圧EST锛� - */ public static void deleteForRest(String uri) { RestTemplate rest = getRestTemplate(); rest.delete(uri); } - /** - * DELETE璇锋眰锛圧EST锛� - */ public static void deleteForRest(String uri, Map<String, Object> map) { RestTemplate rest = getRestTemplate(); -- Gitblit v1.9.3