Skip to content

Commit bdf1ad1

Browse files
committed
Server:同步eclipse版至idea版
1 parent 46254f5 commit bdf1ad1

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

APIJSON(Server)/APIJSON(Idea)/src/main/java/apijson/demo/server/model/Request.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ public String getDescription() {
7171
public void setDescription(String description) {
7272
this.description = description;
7373
}
74-
}
74+
}

APIJSON(Server)/APIJSON(Idea)/src/main/java/zuo/biao/apijson/server/APIJSONApplication.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
import org.springframework.boot.SpringApplication;
1818
import org.springframework.boot.autoconfigure.SpringBootApplication;
19+
import org.springframework.context.annotation.Bean;
20+
import org.springframework.web.cors.CorsConfiguration;
21+
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
22+
import org.springframework.web.filter.CorsFilter;
1923

2024
/**application
2125
* @author Lemon
@@ -38,4 +42,29 @@ public static void main(String[] args) {
3842
e.printStackTrace();
3943
}
4044
}
45+
46+
47+
48+
49+
/**
50+
* 跨域过滤器
51+
* @return
52+
*/
53+
@Bean
54+
public CorsFilter corsFilter() {
55+
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
56+
source.registerCorsConfiguration("/**", buildConfig()); // 4
57+
return new CorsFilter(source);
58+
}
59+
/**CORS跨域配置
60+
* @return
61+
*/
62+
private CorsConfiguration buildConfig() {
63+
CorsConfiguration corsConfiguration = new CorsConfiguration();
64+
corsConfiguration.addAllowedOrigin("*");
65+
corsConfiguration.addAllowedHeader("*");
66+
corsConfiguration.addAllowedMethod("*");
67+
return corsConfiguration;
68+
}
69+
4170
}

0 commit comments

Comments
 (0)