forked from rongchao/epmet-cloud-rizhao
				
			
				 3 changed files with 30 additions and 59 deletions
			
			
		| @ -1,52 +0,0 @@ | |||
| package com.epmet.openapi.scan.config; | |||
| 
 | |||
| import com.alibaba.fastjson.serializer.SerializerFeature; | |||
| import com.alibaba.fastjson.support.config.FastJsonConfig; | |||
| import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; | |||
| import org.springframework.boot.autoconfigure.http.HttpMessageConverters; | |||
| import org.springframework.context.annotation.Bean; | |||
| import org.springframework.context.annotation.Configuration; | |||
| import org.springframework.http.MediaType; | |||
| import org.springframework.http.converter.HttpMessageConverter; | |||
| import org.springframework.http.converter.StringHttpMessageConverter; | |||
| 
 | |||
| import java.nio.charset.Charset; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| 
 | |||
| /** | |||
|  * @author jianjun liu | |||
|  * @email liujianjun@yunzongnet.com | |||
|  * @date 2020-06-05 14:14 | |||
|  **/ | |||
| @Configuration | |||
| public class FastJsonConfiguration { | |||
| 
 | |||
| 	@Bean | |||
| 	public HttpMessageConverters fastJsonHttpMessageConverters() { | |||
| 		FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); | |||
| 		FastJsonConfig fastJsonConfig = new FastJsonConfig(); | |||
| 
 | |||
| 		List<MediaType> fastMediaTypes = new ArrayList<>(); | |||
| 
 | |||
| 		// 处理中文乱码问题
 | |||
| 		fastJsonConfig.setCharset(Charset.forName("UTF-8")); | |||
| 		fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); | |||
| 		// 设置时间格式
 | |||
| 		fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
| 
 | |||
| 		fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); | |||
| 		fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes); | |||
| 
 | |||
| 		// 在转换器中添加配置信息
 | |||
| 		fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); | |||
| 		HttpMessageConverter converter = fastJsonHttpMessageConverter; | |||
| 
 | |||
| 		StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(); | |||
| 		stringConverter.setDefaultCharset(Charset.forName("UTF-8")); | |||
| 		stringConverter.setSupportedMediaTypes(fastMediaTypes); | |||
| 
 | |||
| 		return new HttpMessageConverters(stringConverter, converter); | |||
| 	} | |||
| 
 | |||
| } | |||
					Loading…
					
					
				
		Reference in new issue