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

前端 未结 2 729
抹茶落季
抹茶落季 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-24 10:44

    I had a similar problem and found that Spring Boot has "forceEncoding" enabled by default. This causes the request charset to be overridden and set to UTF-8 every time in their filter.

    See Appendix A. Common application properties

    The key part is:

    Defaults to true when "force" has not been specified.

    So setting either

    spring.http.encoding.force=false
    

    or

    spring.http.encoding.force-request=false
    

    Should solve your problem, as long as the request has the correct headers.

提交回复
热议问题