package com.qiaoba.module.file.config;

import cn.hutool.core.util.URLUtil;
import com.qiaoba.common.base.constant.BaseConstant;
import lombok.Getter;
import lombok.Setter;
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;

/**
 * 配置静态文件资源服务器
 *
 * @author ailanyin
 * @version 1.0
 * @since 2022/2/28 0028 上午 9:12
 */
@Configuration
@Getter
@Setter
public class FileConfig implements WebMvcConfigurer {

    @Value("${qiaoba.file-upload-path}")
    private String uploadPath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(BaseConstant.RESOURCE_PATTERN)
                .addResourceLocations(URLUtil.FILE_URL_PREFIX + uploadPath);

    }
}
