restTemplate 工具类
比自己封装的http工具靠谱,毕竟feign和ribbon也用这个,没有那么多需要考虑的地方,apollo也基于restTemplate封装了一个工具类。默认用的是HttpURLConnection。和okhttp比起来也差不了多少,本人在本地测了一下 import org.springframework.http.*; import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; import java.util.Map; /** * @author liyhu * @date 2019年09月06日 */ public class RestTemplateUtil { /** * 实际执行请求的template */ private static RestTemplate restTemplate=new RestTemplate(); /** * json请求 * @param url * @param entity * @param cls * @param <T> * @return */ public static <T>T post