av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

Spring前后端跨域請求設置代碼實例

瀏覽:64日期:2023-08-25 16:27:09

前后端項目分離,跨域請求時,后端的兩種配置方式:

1.配置類:

package com.helq3.config;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.web.cors.CorsConfiguration;import org.springframework.web.cors.UrlBasedCorsConfigurationSource;import org.springframework.web.filter.CorsFilter;/** * 跨域全局配置 */@Configurationpublic class CorsConfig { private CorsConfiguration buildConfig(){ CorsConfiguration configuration = new CorsConfiguration(); //設置屬性 //允許跨域請求的地址,*表示所有 configuration.addAllowedOrigin('*'); //配置跨域的請求頭 configuration.addAllowedHeader('*'); //配置跨域的請求方法 configuration.addAllowedMethod('*'); //表示跨域請求的時候使用的是否是同一個session configuration.setAllowCredentials(true); return configuration; } @Bean public CorsFilter corsFilter(){ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration('/**',buildConfig()); return new CorsFilter(source); }}

2.Controller上面配置

@CrossOrigin(origins = '*',allowedHeaders = '*',methods = {},allowCredentials = 'true')public class TestController {}

3.Ant Design Vue 中,在src/util/request.js中增加

axios.defaults.withCredentials = true

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 请别相信他免费喜剧电影在线观看 | 精品国产一区二区三区日日嗨 | 久久久视频在线 | 久久免费精彩视频 | 黄色片网站在线观看 | 三级成人在线 | 国产91在线播放 | 久久国产一区二区三区 | 午夜精品网站 | 99国产精品视频免费观看一公开 | 日本一区二区三区四区 | 久久久久久99 | 91久久精品| 中文字幕日韩欧美 | 97精品视频在线 | 电影午夜精品一区二区三区 | 有码在线| 天天天插 | 一区二区三区在线免费看 | 一区二区成人 | 国产在线一级片 | 一区二区国产精品 | 国产视频一区二区 | 国产亚洲成av人片在线观看桃 | 亚洲第一网站 | h视频在线播放 | 亚洲午夜av | 成人一区二区三区在线 | 日韩伦理一区二区 | 精品久久久久久亚洲精品 | 三级黄色片在线观看 | 91精品国产91久久综合桃花 | 精品欧美一区二区久久久伦 | 亚洲成人动漫在线观看 | 色噜噜亚洲男人的天堂 | 免费同性女女aaa免费网站 | 久久精品91久久久久久再现 | 国产区在线看 | 人人人人干 | 99精品在线 | 特级丰满少妇一级aaaa爱毛片 |