1.@CrossOrigin注解
springmvc提供了@CrossOrigin注解在controller层加上注解@CrossOrigin注解进行前后端的跨域问题的解决,代码如下:
@CrossOrigin
@PostMapping("/findAll2")
public Map findAll2(){
Map map=new HashMap();
List<Studentinfo> studentinfos = studentinfoMapper.selectList(null);
map.put("code",0);
map.put("msg","");
map.put("count",0);
map.put("data",studentinfos);
return map;
}
2.nginx (engine x)反向代理
需要下载安装nginx软件,打开nginx目录下conf目录里面nginx.conf文件,配置文件内容,可以配置客户端跨域或服务端跨域,两种方式解决跨域问题,具体配置百度。
3.springboot设置cors跨域
CORS(Cross-origin resource sharing-跨源资源共享)允许网页从其他域向浏览器请求额外的资源,例如字体,CSS或来自CDN的静态图像。 CORS有助于将来自多个域的网页内容提供给通常具有相同安全策略的浏览器。