spEL(Spring表达式语言)有哪些有效用途? [英] What are some valid uses for spEL (Spring Expression Language) ?

查看:417
本文介绍了spEL(Spring表达式语言)有哪些有效用途?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看spring表达式语言,如果您用于配置xml文件,这似乎很有用.但是,参考文档提供了许多使用以下代码的示例:

I was looking at spring expression language and it seems very useful if you are using for configuration xml files. However, the reference docs provide lot of examples that use the following code below:

ExpressionParser parser = new SpelExpressionParser();

String name = parser.parseExpression

何时以及为什么要使用它,因为我可以使用常规java来完成所有操作.我是否缺少一些可能方便使用SpelExpressionParser的功能或其他用途?我不知道还有其他spEL用例吗?

When and why would I be using this as I can do all of it using regular java. Am I missing some features or other uses where SpelExpressionParser could be handy? Are there other uses cases for spEL that I'm not aware of?

推荐答案

您可以将SpEL用作Java反射的简化替代方案.它为您减少了很多代码.
我在工作中遇到的一种用例是将深层对象图展平为名称-值对,以进行索引和查找.

You can use SpEL as a simplified alternative to Java reflection. It reduces a lot of code for you.
One of the use cases, I had at my work is to flatten a deep object graph to a name-value pair for indexing and lookup purposes.

我们的客户可以扩展对象图,在这种情况下,还应该为附加属性建立索引.通过使用SpEL,客户只需要在一些属性文件中编写表达式,框架代码就可以提取新数据.

The object graph can be extended by our customers in which case the additional properties should also be indexed. By using SpEL, the customers only need to write expressions in some properties file and the framework code takes care of extracting the new data.

所有 Java反射用例也是SpEL具有以下用途的潜在用例:增加了简单性并减少了代码.

All the use-cases of Java reflection are also potential use-cases for SpEL with added simplicity and reduced code.

这篇关于spEL(Spring表达式语言)有哪些有效用途?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆