如何在SpringBoot中配置CharacterEncodingFilter?
我在学习Spring Boot时遇到了一些编码问题;我想添加一个像Spring 3.x一样的CharacterEncodingFilter。像这样:
<filter> <filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
回答:
上面的注释中建议的Application.java类的示例代码:
@Beanpublic FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setForceEncoding(true);
characterEncodingFilter.setEncoding("UTF-8");
registrationBean.setFilter(characterEncodingFilter);
return registrationBean;
}
以上是 如何在SpringBoot中配置CharacterEncodingFilter? 的全部内容, 来源链接: utcz.com/qa/435186.html