package com.zhentao.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web MVC 配置
 * 用于配置静态资源访问
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Value("${dynamic.media.upload.path}")
    private String uploadPath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置静态资源映射
        // 访问 /media/** 时，映射到本地存储路径
        registry.addResourceHandler("/media/**")
                .addResourceLocations("file:" + uploadPath);
        
        System.out.println("========== 静态资源映射配置 ==========");
        System.out.println("访问路径: /media/**");
        System.out.println("物理路径: file:" + uploadPath);
        System.out.println("=====================================");
    }
}

