1、问题描述
项目中封装了个restTemplate的静态调用类,分享下,希望能帮到需要的朋友。
2、解决方案
2.1 简要说明:
以前用httpclient用的比较多,后来开始用restTemplate,查了两者的区别,大部分无非就是:
(1)restTemplate是包含在spring包中的,使用起来更加方便一些,调用也简洁一些;
(2)restTemplate的低层支持多种调用,比如:httpclient、HttpURLConnection等吧;
个人认为两者都是为了发送http请求,本质上区别不大,无非就是restTemplate又做了一层封装,使用起来更加方便,代码更加简洁而已。。
2.2 静态调用类
完整代码:
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.Map;
/**
* http调用工具类,软件老王
*/
publ