From f0f69dd73169401123bbb179bfa54a2d084c943a Mon Sep 17 00:00:00 2001 From: Strelitzia Date: Sun, 6 Nov 2022 18:04:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85restTemplate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...linaMappingJackson2HttpMessageConverter.java | 17 +++++++++++++++++ .../angelinaBot/config/RestTemplateConfig.java | 15 +++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/main/java/top/angelinaBot/config/AngelinaMappingJackson2HttpMessageConverter.java create mode 100644 src/main/java/top/angelinaBot/config/RestTemplateConfig.java diff --git a/src/main/java/top/angelinaBot/config/AngelinaMappingJackson2HttpMessageConverter.java b/src/main/java/top/angelinaBot/config/AngelinaMappingJackson2HttpMessageConverter.java new file mode 100644 index 0000000..b61ca02 --- /dev/null +++ b/src/main/java/top/angelinaBot/config/AngelinaMappingJackson2HttpMessageConverter.java @@ -0,0 +1,17 @@ +package top.angelinaBot.config; + +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; + +import java.util.ArrayList; +import java.util.List; + +public class AngelinaMappingJackson2HttpMessageConverter extends MappingJackson2HttpMessageConverter { + + public AngelinaMappingJackson2HttpMessageConverter(){ + List mediaTypes = new ArrayList<>(); + mediaTypes.add(MediaType.TEXT_PLAIN); + mediaTypes.add(MediaType.TEXT_HTML); + setSupportedMediaTypes(mediaTypes); + } +} diff --git a/src/main/java/top/angelinaBot/config/RestTemplateConfig.java b/src/main/java/top/angelinaBot/config/RestTemplateConfig.java new file mode 100644 index 0000000..1616ed6 --- /dev/null +++ b/src/main/java/top/angelinaBot/config/RestTemplateConfig.java @@ -0,0 +1,15 @@ +package top.angelinaBot.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class RestTemplateConfig { + @Bean("restTemplate") + public RestTemplate restTemplate() { + RestTemplate restTemplate = new RestTemplate(); + restTemplate.getMessageConverters().add(new AngelinaMappingJackson2HttpMessageConverter()); + return restTemplate; + } +}