中文乱码问题解决配置

1.application.properties 文件配置统一编码格式

# 编码设置

banner.charset=UTF-8

server.tomcat.uri-encoding=UTF-8

spring.http.encoding.charset=UTF-8

spring.http.encoding.enabled=true

spring.http.encoding.force=true

spring.messages.encoding=UTF-8


2.config  java配置返回编码




import java.nio.charset.Charset;import java.util.List;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.web.servlet.config.annotation.ContentNegotiationConfigurer;import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;/** * 解决中文乱码问题 * @author 史恒飞 ,tel:18516417728 * @version 1.0 ,2018年3月26日上午9:58:19 */@Configurationpublic class CustomMVCConfiguration extends WebMvcConfigurerAdapter { @Bean public HttpMessageConverterresponseBodyConverter() { StringHttpMessageConverter converter = new StringHttpMessageConverter( Charset.forName("UTF-8")); return converter; } @Override public void configureMessageConverters( List> converters) {

        super.configureMessageConverters(converters);

        converters.add(responseBodyConverter());

    }

    @Override

    public void configureContentNegotiation(

            ContentNegotiationConfigurer configurer) {

        configurer.favorPathExtension(false);

    }

}


你可能感兴趣的:(中文乱码问题解决配置)