ResourcesConfig.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package com.onemap.overlap.config;
  2. import com.onemap.common.core.web.domain.RequestResult;
  3. import com.onemap.overlap.utils.SpatialiteUtils;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.beans.factory.annotation.Value;
  6. import org.springframework.context.annotation.Configuration;
  7. import org.springframework.stereotype.Component;
  8. import org.springframework.web.servlet.config.annotation.CorsRegistry;
  9. import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
  10. import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  11. import java.io.File;
  12. import java.sql.Connection;
  13. import java.sql.ResultSet;
  14. import java.sql.Statement;
  15. import java.util.ArrayList;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. /**
  20. * 通用映射配置
  21. *
  22. * @author onemap
  23. */
  24. //@Configuration
  25. @Component
  26. public class ResourcesConfig implements WebMvcConfigurer {
  27. // @Value("${spatialite.filepath}")
  28. // String dbpath;
  29. @Value("${file.temp}")
  30. String tempfilepath;
  31. @Value("${file.proxy}")
  32. String proxypath;
  33. // private ResourceHandlerRegistry curregistry;
  34. // @Autowired
  35. // public ResourcesConfig(ResourceHandlerRegistry registry) {
  36. // this.curregistry = registry;
  37. // }
  38. @Override
  39. public void addResourceHandlers(ResourceHandlerRegistry registry) {
  40. registry.addResourceHandler(proxypath + "/**")
  41. .addResourceLocations("file:" + tempfilepath + File.separator);
  42. // this.curregistry = registry;
  43. // try {
  44. // Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
  45. // Statement statement = connection.createStatement();
  46. // String querySQL = "select * from t_analyse_vector";
  47. // ResultSet resultSet = statement.executeQuery(querySQL);
  48. // while (resultSet.next()) {
  49. // registry.addResourceHandler(resultSet.getString("tablename") + "/**")
  50. // .addResourceLocations("file:" + resultSet.getString("path") + File.separator);
  51. // }
  52. // connection.close();
  53. // } catch (Exception e) {
  54. // e.printStackTrace();
  55. // }
  56. }
  57. // 动态添加新的资源映射
  58. // public void addDynamicResourceMapping(String pathPattern, String location) {
  59. // curregistry.addResourceHandler(pathPattern + "/**")
  60. // .addResourceLocations("file:" + location + File.separator);
  61. // }
  62. }