mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-11-04 08:06:12 +08:00 
			
		
		
		
	!479 StrUtils.maxLength会强制给后面加三个点,哪怕长度没有超过,优化长度不超过不加...
Merge pull request !479 from 重楼/jjjjjjjj/dev
This commit is contained in:
		@ -1,7 +1,7 @@
 | 
				
			|||||||
package cn.iocoder.yudao.framework.common.util.collection;
 | 
					package cn.iocoder.yudao.framework.common.util.collection;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.Arrays;
 | 
					import cn.hutool.core.collection.CollUtil;
 | 
				
			||||||
import java.util.HashSet;
 | 
					
 | 
				
			||||||
import java.util.Set;
 | 
					import java.util.Set;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -13,7 +13,7 @@ public class SetUtils {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @SafeVarargs
 | 
					    @SafeVarargs
 | 
				
			||||||
    public static <T> Set<T> asSet(T... objs) {
 | 
					    public static <T> Set<T> asSet(T... objs) {
 | 
				
			||||||
        return new HashSet<>(Arrays.asList(objs));
 | 
					        return CollUtil.newHashSet(objs);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,6 @@
 | 
				
			|||||||
package cn.iocoder.yudao.framework.common.util.string;
 | 
					package cn.iocoder.yudao.framework.common.util.string;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import cn.hutool.core.lang.Assert;
 | 
				
			||||||
import cn.hutool.core.util.ArrayUtil;
 | 
					import cn.hutool.core.util.ArrayUtil;
 | 
				
			||||||
import cn.hutool.core.util.StrUtil;
 | 
					import cn.hutool.core.util.StrUtil;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -16,7 +17,14 @@ import java.util.stream.Collectors;
 | 
				
			|||||||
public class StrUtils {
 | 
					public class StrUtils {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static String maxLength(CharSequence str, int maxLength) {
 | 
					    public static String maxLength(CharSequence str, int maxLength) {
 | 
				
			||||||
        return StrUtil.maxLength(str, maxLength - 3); // -3 的原因,是该方法会补充 ... 恰好
 | 
					        Assert.isTrue(maxLength > 0);
 | 
				
			||||||
 | 
					        if (null == str) {
 | 
				
			||||||
 | 
					            return null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (str.length() <= maxLength) {
 | 
				
			||||||
 | 
					            return str.toString();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return StrUtil.sub(str, 0, maxLength - 3) + "..."; // -3 的原因,是该方法会补充 ... 恰好
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -45,4 +53,7 @@ public class StrUtils {
 | 
				
			|||||||
        return Arrays.stream(longs).boxed().collect(Collectors.toList());
 | 
					        return Arrays.stream(longs).boxed().collect(Collectors.toList());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static void main(String[] args) {
 | 
				
			||||||
 | 
					        System.out.println(maxLength("aaaaa", 4));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user