mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-10-31 10:37:41 +08:00 
			
		
		
		
	【代码优化】 简化滑动脱敏处理器实现
This commit is contained in:
		| @ -26,19 +26,14 @@ public abstract class AbstractSliderDesensitizationHandler<T extends Annotation> | |||||||
|         int suffixKeep = getSuffixKeep(annotation); |         int suffixKeep = getSuffixKeep(annotation); | ||||||
|         String replacer = getReplacer(annotation); |         String replacer = getReplacer(annotation); | ||||||
|         int length = origin.length(); |         int length = origin.length(); | ||||||
|  |  | ||||||
|         // 情况一:原始字符串长度小于等于保留长度,则原始字符串全部替换 |  | ||||||
|         if (prefixKeep >= length || suffixKeep >= length) { |  | ||||||
|             return buildReplacerByLength(replacer, length); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         // 情况二:原始字符串长度小于等于前后缀保留字符串长度,则原始字符串全部替换 |  | ||||||
|         if ((prefixKeep + suffixKeep) >= length) { |  | ||||||
|             return buildReplacerByLength(replacer, length); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         // 情况三:原始字符串长度大于前后缀保留字符串长度,则替换中间字符串 |  | ||||||
|         int interval = length - prefixKeep - suffixKeep; |         int interval = length - prefixKeep - suffixKeep; | ||||||
|  |  | ||||||
|  |         // 情况一:原始字符串长度小于等于前后缀保留字符串长度,则原始字符串全部替换 | ||||||
|  |         if (interval <= 0) { | ||||||
|  |             return buildReplacerByLength(replacer, length); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // 情况二:原始字符串长度大于前后缀保留字符串长度,则替换中间字符串 | ||||||
|         return origin.substring(0, prefixKeep) + |         return origin.substring(0, prefixKeep) + | ||||||
|                 buildReplacerByLength(replacer, interval) + |                 buildReplacerByLength(replacer, interval) + | ||||||
|                 origin.substring(prefixKeep + interval); |                 origin.substring(prefixKeep + interval); | ||||||
| @ -52,11 +47,7 @@ public abstract class AbstractSliderDesensitizationHandler<T extends Annotation> | |||||||
|      * @return 构建后的替换符 |      * @return 构建后的替换符 | ||||||
|      */ |      */ | ||||||
|     private String buildReplacerByLength(String replacer, int length) { |     private String buildReplacerByLength(String replacer, int length) { | ||||||
|         StringBuilder builder = new StringBuilder(); |         return replacer.repeat(length); | ||||||
|         for (int i = 0; i < length; i++) { |  | ||||||
|             builder.append(replacer); |  | ||||||
|         } |  | ||||||
|         return builder.toString(); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 mcwindy
					mcwindy