whyclxw
2025-05-28 e16302f9d475c7cc4dd18c5abf1a23cb5502e362
src/main/java/com/whyc/config/StaticResourceConfig.java
@@ -1,6 +1,7 @@
package com.whyc.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.whyc.constant.YamlProperties;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -33,7 +34,7 @@
        registry.addResourceHandler("/map/library/*").addResourceLocations("classpath:/META-INF/resources/map/library/");
        //registry.addResourceHandler("/login.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("*.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addR  esourceHandler("*.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
        registry.addResourceHandler("/service-worker.js").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/license/**").addResourceLocations("classpath:/META-INF/resources/config/");
@@ -47,6 +48,7 @@
        File jarFile = applicationHome.getDir();
        //在jar包所在目录下生成一个upload文件夹用来存储上传的图片
        //开发路径
        //String dirPath = jarFile.getParentFile().toString()+File.separator+"fg_photo_3DStation"+File.separator;
        //打包路径
@@ -54,10 +56,32 @@
        registry.addResourceHandler("/fg_photo_3DStation/**").addResourceLocations("file:/"+dirPath);
        //开发路径
        //String dirPathA059 = jarFile.getParentFile().toString()+File.separator+"A059"+File.separator+"images"+File.separator;
        String dirPathA059 = jarFile.getParentFile().toString()+File.separator+"A059"+File.separator+"images"+File.separator;
        //打包路径
        String dirPathA059 = jarFile.toString()+File.separator+"A059"+File.separator+"images"+File.separator;
        registry.addResourceHandler("/A059/**").addResourceLocations("file:"+dirPathA059);
        //String dirPathA059 = jarFile.toString()+File.separator+"A059"+File.separator+"images"+File.separator;
        registry.addResourceHandler("/A059/images/**").addResourceLocations("file:"+dirPathA059);
        /**统一图片上传路径格式*/
        String baseDirPathmap;//百度地图
        String baseDirPath2;
        String baseDirFilePath;
        if(YamlProperties.runModel == 1) {
            //开发路径
            baseDirPathmap = jarFile.getParentFile().toString()+File.separator+"baidumapv2"+File.separator;
            baseDirPath2 = jarFile.getParentFile().toString()+File.separator+"fg_photo"+File.separator;
            baseDirFilePath = jarFile.getParentFile().toString()+File.separator+"fg_file"+File.separator;
        }else {
            //打包路径
            baseDirPathmap = jarFile.toString()+File.separator+"baidumapv2"+File.separator;
            baseDirPath2 = jarFile.toString()+File.separator+"fg_photo"+File.separator;
            baseDirFilePath = jarFile.toString()+File.separator+"fg_file"+File.separator;
        }
        //registry.addResourceHandler("/**").addResourceLocations("file:/"+baseDirPath);
        registry.addResourceHandler("/fg_photo/**").addResourceLocations("file:/"+baseDirPath2);
        registry.addResourceHandler("/baidumapv2/**").addResourceLocations("file:/"+baseDirPathmap);
        registry.addResourceHandler("/fg_file/**").addResourceLocations("file:/"+baseDirFilePath);
        super.addResourceHandlers(registry);