How to config spring boot application to support both UTF-8 and GBK encode?

前端 未结 2 725
抹茶落季
抹茶落季 2021-01-24 09:59

I am using spring boot in my project and I run some encoding issue.

In the project, there is a controller(below) which accept request with a content type header ,\"appli

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-24 10:41

    Adding the CharacterEncodingFilter bean can solve the problem ,seeing form https://github.com/spring-projects/spring-boot/issues/1182

    @Bean
    CharacterEncodingFilter characterEncodingFilter() {
        CharacterEncodingFilter filter = new CharacterEncodingFilter();
        filter.setEncoding("UTF-8");
        filter.setForceEncoding(true);
        return filter;
    }
    

提交回复
热议问题