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;
|
}
|
}
|
}
|