blob: 900553eaf744386e5533d7a888783307d3658527 [file] [log] [blame]
JinGefe5140c2025-06-06 20:07:42 +08001// package com.example.myproject.config;
2
3// import org.springframework.context.annotation.Configuration;
4// import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
5// import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6
7// @Configuration
8// public class WebConfig implements WebMvcConfigurer {
9// @Override
10// public void addResourceHandlers(ResourceHandlerRegistry registry) {
11// // 访问 /uploads/** 映射到本地 D:/Desktop/echo/echo-backend/uploads/
12// registry.addResourceHandler("/uploads/**")
13// .addResourceLocations("file:D:/PT/echo-backend/uploads/");
14// registry.addResourceHandler("/torrent-images/**")
15// .addResourceLocations("file:./uploads/torrents/");
16// }
17// }
22301138c1017df2025-06-05 16:11:39 +080018package com.example.myproject.config;
19
20import org.springframework.context.annotation.Configuration;
21import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
22import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
23
24@Configuration
25public class WebConfig implements WebMvcConfigurer {
26 @Override
27 public void addResourceHandlers(ResourceHandlerRegistry registry) {
JinGefe5140c2025-06-06 20:07:42 +080028 // 这里相对路径是相对于启动目录,比如在项目根目录启动则是 ./uploads/
22301138c1017df2025-06-05 16:11:39 +080029 registry.addResourceHandler("/uploads/**")
JinGefe5140c2025-06-06 20:07:42 +080030 .addResourceLocations("file:./uploads/");
31
32// registry.addResourceHandler("/torrent-images/**")
33// .addResourceLocations("file:./uploads/torrents/");
22301138c1017df2025-06-05 16:11:39 +080034 }
35}
JinGefe5140c2025-06-06 20:07:42 +080036
37