Преглед на файлове

联考版-v3.1.0-图片访问路径问题

xiaof преди 2 години
родител
ревизия
5e63bb0ff5
променени са 1 файла, в които са добавени 10 реда и са изтрити 5 реда
  1. 10 5
      stmms-ms-commons/src/main/java/cn/com/qmth/stmms/ms/commons/config/ImageServerConfig.java

+ 10 - 5
stmms-ms-commons/src/main/java/cn/com/qmth/stmms/ms/commons/config/ImageServerConfig.java

@@ -1,5 +1,6 @@
 package cn.com.qmth.stmms.ms.commons.config;
 
+import org.apache.commons.lang.StringUtils;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.stereotype.Component;
 
@@ -27,14 +28,14 @@ public class ImageServerConfig {
     private String dir;
 
     public String getIp() {
-        try {
+        /*try {
             if (ip == null || ip.isEmpty()) {
                 ip = InetAddress.getLocalHost().getHostAddress();
 
             }
         } catch (UnknownHostException e) {
             e.printStackTrace();
-        }
+        }*/
         return ip;
     }
 
@@ -51,7 +52,7 @@ public class ImageServerConfig {
     }
 
     public String getPort() {
-        return (port == null || port.isEmpty()) ? "3000" : port;
+        return port;
     }
 
     public void setPort(String port) {
@@ -60,9 +61,13 @@ public class ImageServerConfig {
 
     public String getImageServer() {
         if (aliyunOss) {
-            return aliYunOssConfig.getUrl() + File.separator + this.getDir() + File.separator+ "upload";
+            return aliYunOssConfig.getUrl() + File.separator + this.getDir() + File.separator + "upload";
         } else {
-            return "http://" + this.getIp() + ":" + this.getPort() + File.separator + "upload";
+            if(StringUtils.isNotBlank(ip) && StringUtils.isNotBlank(port)){
+                return "http://" + this.getIp() + ":" + this.getPort() + File.separator + "upload";
+            } else {
+                return "upload";
+            }
         }
     }