Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🆕 add spring-boot-test #14

Merged
merged 5 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions spring-boot-nebula-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<spotless-maven-plugin.version>2.43.0</spotless-maven-plugin.version>

</properties>




<dependencyManagement>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand All @@ -46,20 +47,21 @@ public static Object parse(String expressionString, Method method, Object[] args
}
// 获取被拦截方法参数名列表
LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();
String[] paramNameArr = discoverer.getParameterNames(method);
// SPEL解析
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("#");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.nebula.web.common.utils;

/**
* @author : wh
* @date : 2024/6/1 22:12
* @description:
*/
public class ExpressionUtilTest {


}
7 changes: 1 addition & 6 deletions spring-boot-nebula-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@
<groupId>org.springframework.boot</groupId>
<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>
Expand Down
Loading