package com.ruoyi.certif.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.WebMvcConfigurerAdapter;
* @Title: 访问本地(磁盘)图片
* @ClassName: com.ruoyi.certif.config.SourceConfiguration.java
* @Description:
* @author: 王延飞
* @date: 2020/8/14 0014 15:26
* @version V1.0
@Configuration
public class SourceConfiguration extends WebMvcConfigurerAdapter {
* 在配置文件中配置的文件保存路径
@Value("${certif.img.storePath}")
private String imgStorePath;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//其中/cetif/photo表示访问的前缀。"file:imgStorePath"是文件真实的存储路径(如:)
// 访问路径如下:http://localhost:8088/cetif/photo/XXX.png
registry.addResourceHandler("/cetif/photos/**").addResourceLocations("file:"+imgStorePath);
super.addResourceHandlers(registry);
}