//option预检查,直接通过请求
if("OPTIONS".equals(request.getMethod())){
returntrue;
}
// 拦截器中动态设置Origin
Private void corsFilter(HttpServletRequestrequest,HttpServletResponseresponse){
String origin=request.getHeader("Origin");
if(StringUtils.isEmpty(origin)){
origin="*";
}
response.addHeader("Access-Control-Allow-Origin",origin);
response.addHeader("Access-Control-Allow-Methods","*");
response.addHeader("Access-Control-Allow-Credentials","true");
response.addHeader("Access-Control-Allow-Headers","*");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16