[size=medium]获取一个对象的属性是这样写:"${test.a}" 但是外层有$的时候,要去掉
测试发现性能还是挺好的:
1000000次 ===>1243毫秒 100000次 ===>394毫秒
测试代码:
[/size]
使用的jar包版本2.2.7
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-spi</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-api</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-impl</artifactId>
<version>2.2.7</version>
</dependency>
测试发现性能还是挺好的:
1000000次 ===>1243毫秒 100000次 ===>394毫秒
测试代码:
[/size]
package com.eyu.ahxy.module.expression.juel;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import org.junit.Test;
import de.odysseus.el.ExpressionFactoryImpl;
import de.odysseus.el.util.SimpleContext;
/**
* 1000000次 ===>1243毫秒 100000次 ===>394毫秒
* @author bean
*/
public class JuelTest {
public static final int NUM = 1000000;
public int getA() {
return 10;
}
public int getB() {
return 10;
}
String exp = "${Math:min(Math:floor(test.a*test.b),Math:floor(c+d*e))}";
ExpressionFactory factory = new ExpressionFactoryImpl();
SimpleContext context = new SimpleContext();
@Test
public void compileTest() throws Exception {
context.setFunction("Math", "min", Math.class.getMethod("min", int.class, int.class));
context.setFunction("Math", "floor", Math.class.getMethod("floor", double.class));
context.setVariable("test", factory.createValueExpression(new JuelTest(), JuelTest.class));
context.setVariable("c", factory.createValueExpression(10, Integer.class));
context.setVariable("d", factory.createValueExpression(10, Integer.class));
context.setVariable("e", factory.createValueExpression(2, Integer.class));
ValueExpression e = factory.createValueExpression(context, exp, String.class);
for (int i = 0; i < NUM; i++) {
Object result = e.getValue(context);
// System.err.println(result);
}
}
}
使用的jar包版本2.2.7
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-spi</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-api</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-impl</artifactId>
<version>2.2.7</version>
</dependency>