You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
51 lines
1.2 KiB
3 years ago
|
package com.qs.serve.common.util;
|
||
|
|
||
|
import lombok.experimental.UtilityClass;
|
||
|
|
||
|
/**
|
||
|
* @author YenHex
|
||
|
* @since 2022/2/28
|
||
|
*/
|
||
|
@UtilityClass
|
||
|
public class StringUtils extends org.springframework.util.StringUtils {
|
||
|
|
||
|
/** 非空 */
|
||
|
public static boolean isNotEmpty(String str){
|
||
|
return !isEmpty(str);
|
||
|
}
|
||
|
|
||
|
/** 含有空对象 */
|
||
|
public static boolean hasEmpty(Object... strings){
|
||
|
for (Object str : strings) {
|
||
|
if(isEmpty(str)){return true;}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 格式化
|
||
|
* @param exp 含{}的表达式
|
||
|
* @param params 参数(注意跳过空值)
|
||
|
* @return
|
||
|
*/
|
||
|
public static String format(String exp,String... params){
|
||
|
StringBuilder builder = new StringBuilder(exp);
|
||
|
int idx_p = 0;
|
||
|
while (hasText(builder,"{}")){
|
||
|
int idx = builder.indexOf("{}");
|
||
|
if(idx_p<params.length&¶ms[idx_p]!=null){
|
||
|
builder.replace(idx,idx+2,params[idx_p]);
|
||
|
idx_p++;
|
||
|
}else {
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
return builder.toString();
|
||
|
}
|
||
|
|
||
|
private static boolean hasText(StringBuilder a,String text){
|
||
|
return a.toString().contains(text);
|
||
|
}
|
||
|
|
||
|
}
|