拦截器处理前端跨域

1.spingboot拦截器处理前端跨域
@Component

public class Base implements Filter {

@Override
public void init(FilterConfig filterConfig) throws ServletException {

}

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
httpServletResponse.setHeader("Access-Control-Allow-Origin", "*");
httpServletResponse.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE,PATCH,PUT");
httpServletResponse.setHeader("Access-Control-Max-Age", "3600");
//httpServletResponse.setHeader("Access-Control-Allow-Headers", "x-requested-with");
httpServletResponse.setHeader("Access-Control-Allow-Headers", "Content-Type,XFILENAME,XFILECATEGORY,XFILESIZE");
chain.doFilter(request, response);
}

@Override
public void destroy() {

}
}
posted @ 2020-11-24 11:20  a走路带风  阅读(212)  评论(0编辑  收藏  举报