如果 MVel 表达式为真,我需要设置属性的值。任何人都可以帮助我,如何做到这一点。
示例代码如下:
LineItem lineItem = new LineItem();
Address address = new Address();
address.setAddress1("ABC");
address.setAddress2("PA");
lineItem.setShipFromAddress(address);
ParserContext parserContext = ParserContext.create();
parserContext.stronglyTyped().withInput("lineItem",LineItem.class)
.withInput("shipFromAddress", Address.class);
Object compiledWithSet = MVEL.compileExpression("( shipFromAddress.address1 contains 'ABC' || shipFromAddress.address1 contains 'ABC DEF' ) && (shipFromAddress.address2 contains 'PA') ? setShipFromLocation('PA1') : ",parserContext);
MVEL.executeExpression(compiledWithSet, lineItem);