flowable交流群:633168411

flowable通过表达式来获取其值

背景:当我们在实际开发项目的情况,有很多场景是需要知道表达式里面的值,比方说我们要预先知道节点的信息(审批人等等)。

如:

那么如何做呢?

1、解析所有的节点信息,这里我就不说了,上面的博客里面已经写过了。

2、解析表达式具体代码

@Service
public class ExpressionServiceImpl implements IExpressionService {
    private static Logger logger = Logger.getLogger(ExpressionServiceImpl.class);
    @Autowired
    protected ProcessEngineConfigurationImpl processEngineConfiguration;
    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private TypeConverter typeConverter;


    @Override
    public Object getValue(String processInstanceId, String exp) {
        Expression expression = processEngineConfiguration.getExpressionManager().createExpression(exp);
        ExecutionEntity executionEntity = (ExecutionEntity) runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).includeProcessVariables().singleResult();
        return expression.getValue(executionEntity);
    }

    @Override
    public <T> T getValue(String processInstanceId, String exp, Class<T> clazz) {
        Object value = this.getValue(processInstanceId, exp);
        return typeConverter.convert(value, clazz);
    }
}

这样我们就可以获得自己的表达式的值了

posted @ 2019-04-25 10:20  小学生05101  阅读(6090)  评论(0编辑  收藏  举报
flowable交流群:633168411