mirror of https://gitee.com/xiaonuobase/snowy
【修复】修复 #I6IB27 CommonJoinPointUtil类中getArgsJsonString在某些情况下出现bug
parent
d823d3aa1a
commit
8de2c3a838
|
@ -5,7 +5,7 @@ NODE_ENV = development
|
|||
VITE_TITLE = Snowy
|
||||
|
||||
# 接口地址
|
||||
VITE_API_BASEURL = http://127.0.0.1:82
|
||||
VITE_API_BASEURL = http://127.0.0.1:9999
|
||||
|
||||
# 本地端口
|
||||
VITE_PORT = 81
|
||||
|
|
|
@ -12,13 +12,18 @@
|
|||
*/
|
||||
package vip.xiaonuo.common.util;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.Signature;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Spring切面工具类
|
||||
|
@ -35,27 +40,33 @@ public class CommonJoinPointUtil {
|
|||
* @date 2022/9/2 15:51
|
||||
*/
|
||||
public static String getArgsJsonString(JoinPoint joinPoint) {
|
||||
StringBuilder argsJson = new StringBuilder();
|
||||
Signature signature = joinPoint.getSignature();
|
||||
// 参数名数组
|
||||
String[] parameterNames = ((MethodSignature) signature).getParameterNames();
|
||||
// 构造参数组集合
|
||||
Map<String, Object> map = MapUtil.newHashMap();
|
||||
Object[] args = joinPoint.getArgs();
|
||||
for (Object arg : args) {
|
||||
if (!isFilterObject(arg)) {
|
||||
if (ObjectUtil.isNotNull(arg)) {
|
||||
argsJson.append(JSONUtil.toJsonStr(arg)).append(" ");
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if(ObjectUtil.isNotEmpty(args[i]) && isUsefulParam(args[i])) {
|
||||
if(JSONUtil.isTypeJSON(StrUtil.toString(args[i]))) {
|
||||
map.put(parameterNames[i], JSONUtil.parseObj(args[i]));
|
||||
} else {
|
||||
map.put(parameterNames[i], JSONUtil.toJsonStr(args[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return argsJson.toString().trim();
|
||||
return JSONUtil.toJsonStr(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否需要拼接参数,过滤掉HttpServletRequest,MultipartFile,HttpServletResponse等类型参数
|
||||
* 判断是否需要拼接的参数,过滤掉HttpServletRequest,MultipartFile,HttpServletResponse等类型参数
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/9/2 15:51
|
||||
*/
|
||||
private static boolean isFilterObject(Object arg) {
|
||||
return arg instanceof MultipartFile ||
|
||||
arg instanceof HttpServletRequest ||
|
||||
arg instanceof HttpServletResponse;
|
||||
private static boolean isUsefulParam(Object arg) {
|
||||
return !(arg instanceof MultipartFile) &&
|
||||
!(arg instanceof HttpServletRequest) &&
|
||||
!(arg instanceof HttpServletResponse);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#########################################
|
||||
# server configuration
|
||||
#########################################
|
||||
server.port=82
|
||||
server.port=9999
|
||||
|
||||
#########################################
|
||||
# spring profiles configuration
|
||||
|
@ -24,7 +24,7 @@ spring.servlet.multipart.max-file-size=100MB
|
|||
spring.datasource.dynamic.datasource.master.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.datasource.dynamic.datasource.master.url=jdbc:mysql://localhost:3306/snowy?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&useInformationSchema=true
|
||||
spring.datasource.dynamic.datasource.master.username=root
|
||||
spring.datasource.dynamic.datasource.master.password=123456
|
||||
spring.datasource.dynamic.datasource.master.password=12345678
|
||||
spring.datasource.dynamic.strict=true
|
||||
|
||||
# postgres
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
*/
|
||||
package vip.xiaonuo;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
|
||||
/**
|
||||
* TestMain方法
|
||||
*
|
||||
|
@ -20,6 +22,7 @@ package vip.xiaonuo;
|
|||
*/
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
|
||||
String jsonStr = JSONUtil.toJsonStr("dasdasdas,234233|}dasfsed");
|
||||
System.out.println(jsonStr);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue