Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java OGNL能否计算将普通字符串与属性名混合的表达式?_Java_Expression_Ognl - Fatal编程技术网

Java OGNL能否计算将普通字符串与属性名混合的表达式?

Java OGNL能否计算将普通字符串与属性名混合的表达式?,java,expression,ognl,Java,Expression,Ognl,我想用OGNL计算一个表达式,这个表达式包含普通字符串和属性名 单元测试代码: @Test public void evaluate_ognl() throws OgnlException { String expression = "hello:{#this.name}"; Object expr = Ognl.parseExpression(expression); OgnlContext ctx = new OgnlContext(); Studen

我想用OGNL计算一个表达式,这个表达式包含普通字符串和属性名

单元测试代码:

@Test
public void evaluate_ognl() throws OgnlException
{
     String expression = "hello:{#this.name}";
     Object expr = Ognl.parseExpression(expression);
     OgnlContext ctx = new OgnlContext();
     Student s = new Student();
     s.setAge(12);
     s.setName("lig");
     Object value = Ognl.getValue(expr, ctx, s);
     System.out.println(value);
}
Student
类有两个属性:age和name,所以这里我想打印:
hello:lig
,但它没有,它抛出了一个异常,意思是
hello:{this.name}
不是一个合法的表达式,我不知道如何修复它,或者OGNL支持这种混合样式的表达式吗

PS:我找到了一个解决方案:表达式应该是:hello.concat(#this.name)