🆕 add spring-boot-test
This commit is contained in:
parent
45e09d4e20
commit
513f9e52d6
9
pom.xml
9
pom.xml
|
@ -36,6 +36,14 @@
|
|||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
@ -50,7 +58,6 @@
|
|||
</dependencyManagement>
|
||||
|
||||
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache Software License, Version 2.0</name>
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
</properties>
|
||||
|
||||
|
||||
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.nebula.web.common.utils;
|
|||
import com.nebula.base.utils.DataUtils;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Objects;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
|
@ -29,20 +30,20 @@ public class ExpressionUtil {
|
|||
}
|
||||
//获取被拦截方法参数名列表
|
||||
LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();
|
||||
String[] paramNameArr = discoverer.getParameterNames(method);
|
||||
String[] paramNames = discoverer.getParameterNames(method);
|
||||
if (paramNames == null || args == null || paramNames.length != args.length) {
|
||||
throw new IllegalArgumentException("Method parameter names and argument values do not match.");
|
||||
}
|
||||
//SPEL解析
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
for (int i = 0; i < Objects.requireNonNull(paramNameArr).length; i++) {
|
||||
context.setVariable(paramNameArr[i], args[i]);
|
||||
for (int i = 0; i < Objects.requireNonNull(paramNames).length; i++) {
|
||||
context.setVariable(paramNames[i], args[i]);
|
||||
}
|
||||
return parser.parseExpression(expressionString).getValue(context);
|
||||
}
|
||||
|
||||
public static boolean isEl(String param) {
|
||||
if (DataUtils.isEmpty(param)) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(param.substring(0, 1), "#");
|
||||
return !StringUtils.isEmpty(param) && param.startsWith("#");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package com.nebula.web.common.utils;
|
||||
|
||||
/**
|
||||
* @author : wh
|
||||
* @date : 2024/6/1 22:12
|
||||
* @description:
|
||||
*/
|
||||
public class ExpressionUtilTest {
|
||||
|
||||
|
||||
}
|
|
@ -29,11 +29,6 @@
|
|||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
|
|
Loading…
Reference in New Issue