ExpressionParser源码分析
parent
d24dd35aef
commit
543533ca40
|
@ -13,7 +13,7 @@
|
||||||
</p>
|
</p>
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://visitor-badge.lithub.cc/badge?page_id=github.com/xuchengsheng&left_text=Visitors" alt="Visitor Badge"/>
|
<img src="https://visitor-badge.lithub.cc/badge?page_id=github.com/xuchengsheng&left_text=Visitors" alt="Visitor Badge"/>
|
||||||
<img src="https://img.shields.io/badge/WeChat-xcs19930428-%2307C160?logo=wechat" alt="Wechat Badge"/>
|
<img src="https://img.shields.io/badge/WeChat-spring_reading-%2307C160?logo=wechat" alt="Wechat Badge"/>
|
||||||
<a href="https://blog.csdn.net/duzhuang2399"><img src="https://img.shields.io/badge/dynamic/xml?url=https%3A%2F%2Fblog.csdn.net%2Fduzhuang2399&query=%2F%2F*%5B%40id%3D%22userSkin%22%5D%2Fdiv%5B1%5D%2Fdiv%5B2%5D%2Fdiv%5B1%5D%2Fdiv%2Fdiv%5B2%5D%2Fdiv%5B1%5D%2Fdiv%5B1%5D%2Fdiv%5B2%5D%2Fspan&logo=C&logoColor=red&label=CSDN&color=red&cacheSeconds=3600" alt="CSDN Badge"></a>
|
<a href="https://blog.csdn.net/duzhuang2399"><img src="https://img.shields.io/badge/dynamic/xml?url=https%3A%2F%2Fblog.csdn.net%2Fduzhuang2399&query=%2F%2F*%5B%40id%3D%22userSkin%22%5D%2Fdiv%5B1%5D%2Fdiv%5B2%5D%2Fdiv%5B1%5D%2Fdiv%2Fdiv%5B2%5D%2Fdiv%5B1%5D%2Fdiv%5B1%5D%2Fdiv%5B2%5D%2Fspan&logo=C&logoColor=red&label=CSDN&color=red&cacheSeconds=3600" alt="CSDN Badge"></a>
|
||||||
</p>
|
</p>
|
||||||
<p align="center">
|
<p align="center">
|
||||||
|
@ -36,6 +36,7 @@
|
||||||
💻 <a href="#我的-github-统计">统计</a>
|
💻 <a href="#我的-github-统计">统计</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## ⚡技术
|
## ⚡技术
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -17,23 +17,8 @@ public class ExpressionParserDemo {
|
||||||
ExpressionParser parser = new SpelExpressionParser();
|
ExpressionParser parser = new SpelExpressionParser();
|
||||||
|
|
||||||
// 解析基本表达式
|
// 解析基本表达式
|
||||||
try {
|
|
||||||
Expression expression = parser.parseExpression("100 * 2 + 10");
|
Expression expression = parser.parseExpression("100 * 2 + 10");
|
||||||
Integer result = expression.getValue(Integer.class);
|
Integer result = expression.getValue(Integer.class);
|
||||||
System.out.println("表达式 '100 * 2 + 10' 的结果为: " + result);
|
System.out.println("表达式 '100 * 2 + 10' 的结果为: " + result);
|
||||||
} catch (ParseException e) {
|
|
||||||
System.err.println("解析表达式出错: " + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用上下文的解析
|
|
||||||
try {
|
|
||||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
|
||||||
context.setVariable("myVariable", 50);
|
|
||||||
Expression expressionWithContext = parser.parseExpression("100 * #myVariable + 10");
|
|
||||||
Integer resultWithContext = expressionWithContext.getValue(context, Integer.class);
|
|
||||||
System.out.println("带上下文的表达式 '100 * #myVariable + 10' 的结果为: " + resultWithContext);
|
|
||||||
} catch (ParseException e) {
|
|
||||||
System.err.println("解析带上下文的表达式出错: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue