WebMvcConfig.java
940 Bytes
package top.panll.assist.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import top.panll.assist.dto.UserSettings;
import java.io.File;
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Autowired
private UserSettings userSettings;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// TODO windows环境下会报错 因为 路径不正确
File file = new File(userSettings.getRecordTempPath() + File.separator);
registry.addResourceHandler("/download/**").addResourceLocations("file://" + File.separator + file.getAbsolutePath() + "/" );
super.addResourceHandlers(registry);
}
}