2024-02-27 12:53:37 +08:00
|
|
|
package com.zhgd.xmgl.util;
|
|
|
|
|
|
2024-06-01 19:41:18 +08:00
|
|
|
import cn.hutool.core.util.StrUtil;
|
2024-04-12 10:38:25 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
2024-06-01 20:02:23 +08:00
|
|
|
import org.springframework.stereotype.Component;
|
2024-04-12 10:38:25 +08:00
|
|
|
|
2024-06-01 20:02:23 +08:00
|
|
|
@Component
|
2024-02-27 12:53:37 +08:00
|
|
|
public class PathUtil {
|
2024-04-12 10:38:25 +08:00
|
|
|
|
|
|
|
|
private static String basePath;
|
|
|
|
|
|
2024-02-27 12:53:37 +08:00
|
|
|
/**
|
|
|
|
|
* 删除多余的斜杠
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String reviseSlash(String path) {
|
|
|
|
|
return path.replaceAll("([^:])(//+)", "$1/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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"));
|
2024-03-05 09:37:46 +08:00
|
|
|
System.out.println(reviseSlash("http://192.168.34.221:9111/image//65e5733735f013f4cc322278.jpg"));
|
2024-02-27 12:53:37 +08:00
|
|
|
}
|
2024-04-12 10:38:25 +08:00
|
|
|
|
2024-09-05 17:40:44 +08:00
|
|
|
public static String getBasePath() {
|
|
|
|
|
return StrUtil.removeSuffix(basePath, "/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Value("${basePath}")
|
|
|
|
|
public void setBasePath(String basePath) {
|
|
|
|
|
PathUtil.basePath = basePath;
|
|
|
|
|
}
|
2024-02-27 12:53:37 +08:00
|
|
|
}
|