打印sql参数把base64长度超过5000的隐藏

This commit is contained in:
xiangerlin 2025-06-26 15:40:41 +08:00
parent 74beb49df3
commit 9c4b8564e4
1 changed files with 29 additions and 5 deletions

View File

@ -19,10 +19,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.*;
/**
* @ClassName: SqlLogInterceptor
@ -159,7 +156,15 @@ public class SqlLogInterceptor implements Interceptor {
private String getParameterValue(Object obj) {
String value;
if (obj instanceof String) {
if (((String) obj).length() < 5000){
value = "'" + obj.toString() + "'";
}else {
if (!isBase64((String) obj)){
value = "'" + obj.toString() + "'";
}else {
value = "'" +"base64"+ "'";
}
}
} else if (obj instanceof Date) {
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.CHINA);
value = "'" + formatter.format(obj) + "'";
@ -172,4 +177,23 @@ public class SqlLogInterceptor implements Interceptor {
}
return value;
}
/**
* 判断一个字符串是否是Base64编码
*
* @param str 输入的字符串
* @return 如果是Base64编码返回true否则返回false
*/
public static boolean isBase64(String str) {
try {
// 尝试对字符串进行Base64解码
byte[] decodedBytes = Base64.getDecoder().decode(str);
// 解码成功返回true
return true;
} catch (IllegalArgumentException e) {
// 捕获异常返回false
return false;
}
}
}