管道基础大数据平台系统开发-【后端】-Server
13693261870
2024-03-25 b6b0cb226fcf184525ee7b36af3a09471e9c0057
src/main/java/com/lf/server/helper/RestHelper.java
@@ -1,6 +1,7 @@
package com.lf.server.helper;
import com.lf.server.entity.all.StaticData;
import io.swagger.models.HttpMethod;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
@@ -185,12 +186,39 @@
    }
    /**
     * 获取错误信息
     *
     * @param uri Uri地址
     * @param ex  异常
     * @return 错误信息
     */
    public static String getErrorInfo(String uri, Exception ex) {
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("result", null);
        map.put("message", ex.getMessage());
        map.put("code", 400);
        map.put("uri", uri);
        //map.put("tag", StaticData.CACHE_PREFIX)
        return map.toString();
    }
    /**
     * GET请求(REST)
     */
    public static String getForRest(String uri) {
        RestTemplate rest = getRestTemplate();
        return rest.getForObject(uri, String.class);
    }
    /**
     * GET请求(REST)
     */
    public static <T> T getForRest(String uri, Class<T> clazz) {
        RestTemplate rest = getRestTemplate();
        return rest.getForObject(uri, clazz);
    }
    /**
@@ -212,20 +240,20 @@
    }
    /**
     * 获取错误信息
     *
     * @param uri Uri地址
     * @param ex  异常
     * @return 错误信息
     * POST请求(REST)
     */
    public static String getErrorInfo(String uri, Exception ex) {
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("result", null);
        map.put("message", ex.getMessage());
        map.put("code", 400);
        map.put("uri", uri);
        //map.put("tag", StaticData.CACHE_PREFIX)
    public static <T> String postForRest(String uri, T t) {
        RestTemplate rest = getRestTemplate();
        return map.toString();
        return rest.postForObject(uri, t, String.class);
    }
    /**
     * DELETE请求(REST)
     */
    public static void deleteForRest(String uri) {
        RestTemplate rest = getRestTemplate();
        rest.delete(uri);
    }
}