Spring boot http编码配置(CharacterEncodingFilter)

spring web项目中需要在添加CharacterEncodingFilter

springboot中只需要在配置文件中添加以下配置

spring.http.encoding.charset=UTF-8

spring.http.encoding.enabled=true 

spring.http.encoding.force=true 

 

参考springboot官方文档

https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

有以属性可以配置

# HTTP encoding (HttpEncodingProperties)
spring.http.encoding.charset=UTF-8 # Charset of HTTP requests and responses. Added to the "Content-Type" header if not set explicitly.
spring.http.encoding.enabled=true # Whether to enable http encoding support.
spring.http.encoding.force= # Whether to force the encoding to the configured charset on HTTP requests and responses.
spring.http.encoding.force-request= # Whether to force the encoding to the configured charset on HTTP requests. Defaults to true when "force" has not been specified.
spring.http.encoding.force-response= # Whether to force the encoding to the configured charset on HTTP responses.
spring.http.encoding.mapping= # Locale in which to encode mapping.

另外web窗口 tomcat可以配置

server.tomcat.uri-encoding=UTF-8 # Character encoding to use to decode the URI.

你可能感兴趣的:(SpringBoot)