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() {
}
}