JinGe | fe5140c | 2025-06-06 20:07:42 +0800 | [diff] [blame^] | 1 | // 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 | // } |
22301138 | c1017df | 2025-06-05 16:11:39 +0800 | [diff] [blame] | 18 | package com.example.myproject.config; |
| 19 | |
| 20 | import org.springframework.context.annotation.Configuration; |
| 21 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
| 22 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| 23 | |
| 24 | @Configuration |
| 25 | public class WebConfig implements WebMvcConfigurer { |
| 26 | @Override |
| 27 | public void addResourceHandlers(ResourceHandlerRegistry registry) { |
JinGe | fe5140c | 2025-06-06 20:07:42 +0800 | [diff] [blame^] | 28 | // 这里相对路径是相对于启动目录,比如在项目根目录启动则是 ./uploads/ |
22301138 | c1017df | 2025-06-05 16:11:39 +0800 | [diff] [blame] | 29 | registry.addResourceHandler("/uploads/**") |
JinGe | fe5140c | 2025-06-06 20:07:42 +0800 | [diff] [blame^] | 30 | .addResourceLocations("file:./uploads/"); |
| 31 | |
| 32 | // registry.addResourceHandler("/torrent-images/**") |
| 33 | // .addResourceLocations("file:./uploads/torrents/"); |
22301138 | c1017df | 2025-06-05 16:11:39 +0800 | [diff] [blame] | 34 | } |
| 35 | } |
JinGe | fe5140c | 2025-06-06 20:07:42 +0800 | [diff] [blame^] | 36 | |
| 37 | |