标签:this scribe one url 后端 inf 图片 var max
springboot中新增一个过滤器如下:
package com.rtpksps.kss.config;
import org.springframework.stereotype.Component;
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author Administrator
* @title: OriginFilter
* @projectName rtpksps-kss
* @description: TODO
* @date 2019/9/29 0029下午 15:52
*/
@Component
public class OriginFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) servletResponse;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE,PUT");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
filterChain.doFilter(servletRequest, servletResponse);
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void destroy() {
}
}
在接口中指定需要的方法类型
angular页面发送http请求:
标签:this scribe one url 后端 inf 图片 var max
原文地址:https://www.cnblogs.com/lideqiang0909/p/11609284.html