SpringBoot如何设置请求字符串格式为UTF-8呢?
下文笔者讲述SpringBoot设置请求字符串格式的方法分享,如下所示
SpringBoot设置请求字符串的格式 只需设置一个过滤器 采用这种方式 即可对传送数据进行过滤及传送格式设置例:Springboot设置字符串格式为UTF-8
过滤器编码 package com.config; import com.jetsum.business.common.constant.CharsetConstant; import lombok.extern.slf4j.Slf4j; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * 字符过滤器 */ @Slf4j public class CharsetFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; request.setCharacterEncoding(CharsetConstant.UTF_8); response.setCharacterEncoding(CharsetConstant.UTF_8); filterChain.doFilter(servletRequest,servletResponse); } }
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。