本文介绍了Spring已弃用的ExpressionEvaluationUtils的替代方法是评估方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
自上课以来:
自Spring 3.x发布以来已被弃用,我正在为我的java代码中的EL表达式评估寻找另一种选择。
Since the class:org.springframework.web.util.ExpressionEvaluationUtilsis deprecated since Spring 3.x release, I am looking for another alternative for EL expression evaluation in my java code.
在阅读JSP 2.x文档后,我确实设法构建了另一种方法:
After reading JSP 2.x documentation, I did manage to construct an alternative method:
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.servlet.jsp.JspApplicationContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspFactory;
import javax.servlet.jsp.PageContext;
public class ExpressionEvaluationUtils {
public static Object evaluate(String exp, Class<?> resultClass, PageContext pageContext)
throws JspException {
if (pageContext == null){
return exp;
}
ELContext elContext = pageContext.getELContext();
JspFactory jf = JspFactory.getDefaultFactory();
JspApplicationContext jac = jf
.getJspApplicationContext(pageContext.getServletContext());
ExpressionFactory ef = jac.getExpressionFactory();
ValueExpression val = ef.createValueExpression(elContext, exp, resultClass);
return val.getValue(elContext);
}
}
你能否提出更多我的选择实施?
Can you suggest more alternatives to my implementation?
推荐答案
您可以使用以下任何项目:
You could use any of the projects below:
- Apache Commons OGNL
- MVEL
- JBoss EL
- Spring Expression Language (SpEL)
这篇关于Spring已弃用的ExpressionEvaluationUtils的替代方法是评估方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!