最近我试用了JUEL,现在我很困惑如何编写一些在文档中找不到的方法。
只给我这个http://juel.sourceforge.net/guide/start.html
如果我有context.setFunction("meh", "max", BigDecimal.class.getMethod("compareTo", BigDecimal.class));的话,我想知道怎么把它写出来
既然我们知道bigDecimal表达式是像foo.compareTo(bigDecimal);那样写的,那么如何在表达式中写这个呢?
发布于 2019-01-29 03:27:17
用两个可能的答案轻松地完成
SimpleContext允许你做算术计算(在我的例子中),所以我把计算放在这里。我还使用ValueExpression (我猜不是在正确的位置)为我提供来自SimpleContext的映射值。因此,我在这里
context.setVariable("fii",factory.createValueExpression(新BigDecimal(3),BigDecimal.class);context.setVariable("fee",factory.createValueExpression(新BigDecimal(5),BigDecimal.class));ValueExpression e1 =factory.createValueExpression(上下文,"${fee}",BigDecimal.class);ValueExpression e2 =factory.createValueExpression(上下文,"${fii}",BigDecimal.class);String temp1 =( String )e1.getValue(上下文)BigDecimal.class();String factory.createValueExpression=(String)e2.getValue(上下文)();context.setVariable("foo",factory.createValueExpression(新BigDecimal(Temp1).add(新BigDecimal(temp2)),BigDecimal.class);ValueExpression e=factory.createValueExpression(上下文,"${foo}",BigDecimal.class);//将返回8但我又一次不知道这是不是对的,所以我想出了第二个
Operate
公共静态BigDecimal添加(BigDecimal val1,BigDecimal val2){返回val1.add(val2);}公共静态BigDecimal减法(BigDecimal val1,BigDecimal val2){返回值1减去(Val2);}
然后,我称之为thiscontext.setFunction("meh","max",Operate.class.getMethod("add",BigDecimal.class,BigDecimal.class));ValueExpression e=factory.createValueExpression(上下文,"${meh:max(fii,fee)}",BigDecimal.class);//还返回8。我更喜欢用第二个,希望这会有帮助。
https://stackoverflow.com/questions/54394715
复制相似问题