2024-10-29 20:28:39 +08:00

61 lines
1.7 KiB
Java

package com.zhgd.xmgl.util;
import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class PathUtil {
private static String basePath;
private static String serverUrl;
private static String mlTranspondUrl;
/**
* 删除多余的斜杠
*
* @return
*/
public static String reviseSlash(String path) {
return path.replaceAll("([^:])(//+)", "$1/");
}
public static String getServerUrl() {
return StrUtil.removeSuffix(serverUrl, "/");
}
@Value("${serverUrl}")
public void setServerUrl(String serverUrl) {
PathUtil.serverUrl = serverUrl;
}
public static String getMlTranspondUrl() {
return StrUtil.removeSuffix(mlTranspondUrl, "/");
}
@Value("${ml.transpond.url:}")
public void setMlTranspondUrl(String mlTranspondUrl) {
PathUtil.mlTranspondUrl = mlTranspondUrl;
}
public static void main(String[] args) {
System.out.println(reviseSlash("/home//foo/"));
System.out.println(reviseSlash("/home/foo/"));
System.out.println(reviseSlash("/homefoo//"));
System.out.println(reviseSlash("http://192.168.34.221:19111/xmgl/weight/weighInfo/getNewestWeighInfo"));
System.out.println(reviseSlash("http://192.168.34.221:19111/xmgl//weight/weighInfo/getNewestWeighInfo"));
System.out.println(reviseSlash("http://192.168.34.221:9111/image//65e5733735f013f4cc322278.jpg"));
}
public static String getBasePath() {
return StrUtil.removeSuffix(basePath, "/");
}
@Value("${basePath}")
public void setBasePath(String basePath) {
PathUtil.basePath = basePath;
}
}