From f8390684af0998e70be6381d419cd0ac436d8f2f Mon Sep 17 00:00:00 2001 From: zhenghaoyu Date: Fri, 16 Aug 2024 21:43:21 +0800 Subject: [PATCH] =?UTF-8?q?1.=E7=94=9F=E6=88=90=E5=8C=85=E6=9D=A1=E7=A0=81?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E5=93=88=E5=B8=8C=E5=80=BC=E7=9A=84=E8=BE=B9?= =?UTF-8?q?=E7=95=8C=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/springblade/common/utils/CommonUtil.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/blade-biz-common/src/main/java/org/springblade/common/utils/CommonUtil.java b/blade-biz-common/src/main/java/org/springblade/common/utils/CommonUtil.java index b8947397b..be0afab9b 100644 --- a/blade-biz-common/src/main/java/org/springblade/common/utils/CommonUtil.java +++ b/blade-biz-common/src/main/java/org/springblade/common/utils/CommonUtil.java @@ -290,9 +290,17 @@ public class CommonUtil { public static String getHaxCodeByLong(String str,int changdu){ long time = new Date().getTime(); - int hashValue = (str+time).hashCode(); // 获取哈希值(32位) - // 将32位哈希值转换为6位长度的纯数字形式 + int hashValue = (str + time).hashCode(); // 获取哈希值(32位) + + // 将32位哈希值转换为纯数字形式 String s = Math.abs(hashValue) + ""; + + // 检查 changdu 是否超出 s 的长度 + if (changdu > s.length()) { + // 返回整个字符串或根据需求处理 + return s; + } + String substring = s.substring(0, changdu); return substring; }