2021与蓝度共同重构项目,服务端
chenjiantian
2021-11-24 6bdb5dda11b8723ddc20a37b9cbcc1e1fdace13a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.sandu.common.util;
 
import cn.hutool.core.util.StrUtil;
import com.sandu.common.config.CommonProperties;
 
/**
 * @author chenjiantian
 * @date 2021/8/2 15:47
 */
public class ResUtils {
 
    /**
     * 给相对路径资源加域名
     *
     * @param url
     * @return
     */
    public static String addPrefix(String url) {
        if (StrUtil.isBlank(url)) {
            return null;
        }
        if (url.trim().startsWith("http")) {
            return url;
        } else {
            CommonProperties properties = SpringContextHolder.getBean(CommonProperties.class);
            return properties.getUrlPrefix() + url;
        }
    }
 
 
    /**
     * 给相对路径资源去除域名
     *
     * @param url
     * @return
     */
    public static String removePrefix(String url) {
        if (StrUtil.isBlank(url)) {
            return null;
        }
        CommonProperties properties = SpringContextHolder.getBean(CommonProperties.class);
        String urlPrefix = properties.getUrlPrefix();
        if (url.trim().startsWith(urlPrefix)) {
            return StrUtil.subAfter(url.trim(), urlPrefix, false);
        } else {
            return url;
        }
    }
}