package com.ggfw.datamanagement.config; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration public class WebConfig implements WebMvcConfigurer { static final String EXCEL_PATH = System.getProperty("user.dir") + "/excelExport/"; @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/excelExport/**").addResourceLocations("file:" + EXCEL_PATH); } }
这样配置后根目录下的excelExport就会变成静态目录,可以通过http://localhost:post/excelExport来访问,
生成jar包后,与jar包同目录就会变成根目录同样可以访问,解决后端生成某些文件如导出excel后无法通过静态资源路径下载的问题