配置本地资源映射路径 addResourceHandlers
一般我们在访问A(虚拟的)的时候,需要到B(实际的)的位置去访问。
那么我们就需要用到addResourceHandlers。
@Configuration public class UploadConfig implements WebMvcConfigurer { //绝对路径 registry.addResourceHandler("/file/**").addResourceLocations("file:/static/"); //类路径 registry.addResourceHandler("/html/**").addResourceLocations("classpath:/static/"); }
配制:
*/ @Configuration public class UploadConfig implements WebMvcConfigurer { @Value("${file.staticAccessPath}") private String staticAccessPath; @Value("${file.uploadFolder}") private String uploadFolder; @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { // System.out.println("*********************************虚拟路径被使用**************************"); registry.addResourceHandler(staticAccessPath).addResourceLocations("file:" + uploadFolder); } }
注意:
uploadFolder 路径一定要正确(可以上传完后,输出来,然后拷进去,这样100%不会出问题。),并且末尾一定要有/
如果用了shiro/security的话,得放行:
map.put("/file/**", "anon"); map.put("/html/**", "anon");
另一篇: https://www.cnblogs.com/jiduoduo/p/14765398.html
道法自然

浙公网安备 33010602011771号