refactor(music-houduan): 移除基本测试控制器并优化 Web MVC 配置
- 删除了 BasicTestController 类,不再提供基本测试接口 - 优化了 WebMvcConfig 配置类: - 移除了不必要的属性注入 - 简化了资源处理器的配置,直接使用固定的 "/upload/**" 路
This commit is contained in:
@@ -5,24 +5,19 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Web MVC 配置
|
* Web MVC 配置
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class WebMvcConfig implements WebMvcConfigurer {
|
public class WebMvcConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
@Value("${file.upload-path}")
|
@Value("${file.upload-path}")
|
||||||
private String uploadPath;
|
private String uploadPath;
|
||||||
|
|
||||||
@Value("${file.access-path}")
|
|
||||||
private String accessPath;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
// 配置上传文件资源映射
|
registry.addResourceHandler("/upload/**") // 处理这个路径的请求
|
||||||
registry.addResourceHandler(accessPath + "**")
|
.addResourceLocations("file:" + uploadPath + "/"); // 文件路径,映射到本地文件系统
|
||||||
.addResourceLocations("file:" + uploadPath);
|
|
||||||
|
|
||||||
// 注意:前后端分离项目,不需要配置静态资源映射
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
package com.test.musichouduan.controller;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 基本测试控制器
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/basic-test")
|
|
||||||
public class BasicTestController {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 基本测试接口
|
|
||||||
*/
|
|
||||||
@GetMapping
|
|
||||||
public Map<String, Object> test() {
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
result.put("code", 200);
|
|
||||||
result.put("message", "基本测试成功");
|
|
||||||
result.put("data", "Hello, Basic Test!");
|
|
||||||
result.put("time", System.currentTimeMillis());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 61 KiB |
Binary file not shown.
Reference in New Issue
Block a user