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配置类 - 配置静态资源访问
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    
    @Value("${dynamic.media.upload.path}")
    private String uploadPath;
    
    /**
     * 配置静态资源映射
     * 将 /media/** 映射到本地上传目录
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置动态媒体访问路径
        registry.addResourceHandler("/media/**")
                .addResourceLocations("file:" + uploadPath);
        
        System.out.println("========== 静态资源配置 ==========");
        System.out.println("媒体访问路径: /media/**");
        System.out.println("本地存储路径: file:" + uploadPath);
        System.out.println("示例URL: http://localhost:8083/media/dynamic_xxx.jpg");
    }
}

