目录
一、前言
1.SpringBoot需要配置跨域
2.前端使用axios下载txt文件
二、后端SpringBoot接口
1.跨域配置
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;
@Configuration
public class CorsConfig {
private CorsConfiguration buildConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.setAllowCredentials(true);
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
return corsConfiguratio

该博客介绍了使用SpringBoot和前端实现txt文件下载的方法。后端需进行跨域配置和Controller接口编写,要注意避免调用response.reset()方法以免造成跨域问题;前端使用axios下载txt文件,最后还涉及测试环节。
最低0.47元/天 解锁文章
3万+

被折叠的 条评论
为什么被折叠?



