package com.soft.mpms.zframe.config;
import java.io.File;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* 文件路径配置,可以直接访问
* 映射的路径后面必须加/,否则访问不到
*/
@SuppressWarnings("deprecation")
@Configuration
public class FilePathConfig extends WebMvcConfigurerAdapter {
//window临时目录
public static String windowtempfile = "C:/usr/tempfile/";
//liunx临时目录
public static String liunxtempfile = "/usr/tempfile/";
public static String tempfilepath = "/platform/tempfile";
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if(isWindows()) {
//和页面有关的静态目录都放在项目的static目录下
File file = new File(windowtempfile) ;
if(!file.exists()) {
file.mkdirs();
}
registry.addResourceHandler("/tempfile/**").addResourceLocations("file:"+windowtempfile);
}else {
//和页面有关的静态目录都放在项目的static目录下
File file = new File(liunxtempfile) ;
if(!file.exists()) {
file.mkdirs();
}
registry.addResourceHandler("/tempfile/**").addResourceLocations("file:"+liunxtempfile);
}
}
/**
*
* @Title: gettempfilepath
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 参数
* @return String 返回类型
* @throws
*/
public static String gettempfilepath() {
if(isWindows()) {
return windowtempfile;
}else {
return liunxtempfile;
}
}
/**
*
* @Title: isWindows
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 参数
* @return boolean 返回类型
* @throws
*/
public static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().contains("windows");
}
}
标签:web,return,Windows,路径,tempfile,static,file,public
From: https://www.cnblogs.com/hhs-5120/p/16875960.html