|
|
@@ -0,0 +1,52 @@
|
|
|
+package com.usoftchina.saas.sale.config;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.http.converter.HttpMessageConverter;
|
|
|
+import org.springframework.http.converter.StringHttpMessageConverter;
|
|
|
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
|
+import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
|
|
|
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
|
|
+
|
|
|
+import java.nio.charset.Charset;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: guq
|
|
|
+ * @create: 2018-10-30 11:20
|
|
|
+ **/
|
|
|
+
|
|
|
+@Configuration
|
|
|
+public class WebConfig extends WebMvcConfigurationSupport{
|
|
|
+ @Bean
|
|
|
+ public HttpMessageConverter<String> responseBodyConverter() {
|
|
|
+ StringHttpMessageConverter converter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
|
|
|
+ return converter;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public MappingJackson2HttpMessageConverter MappingJacksonHttpMessageConverter(){
|
|
|
+ MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ converter.setObjectMapper(objectMapper);
|
|
|
+ return converter;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
|
+ super.configureMessageConverters(converters);
|
|
|
+ converters.add(responseBodyConverter());
|
|
|
+ converters.add(MappingJacksonHttpMessageConverter());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
|
|
|
+ configurer.favorPathExtension(false);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|