//在项目中添加跨域请求具体配置
@Configuration
public class CorsConfig {
private CorsConfiguration buildConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*");//设置访问源地址
corsConfiguration.addAllowedHeader("*");//设置访问源请求头
corsConfiguration.addAllowedMethod("*");//设置访问源请求方法(get、post等)
return corsConfiguration;
}
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", buildConfig());// 对接口配置跨域设置
return new CorsFilter(source);
}
}
ts和html部分
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
listData: Object;
constructor(public navCtrl: NavController,public http:Http) {
}
printText(){
this.http.request('http://127.0.0.1:8080/institutions/hello')
.subscribe((res: Response) => {
this.listData = res.json();
console.log(this.listData);
});
}
}