Flowable入门系列文章188 - 基于注解的映射语句
flowable入门、flowable现状、flowable开源产品、flwoable入门系列、flowable课程、flowable与activiti区别Flowable是用Java编写的轻量级业务流程引擎。Flowable流程引擎允许您部署BPMN 2.0流程定义(用于定义流程的行业XML标准),创建流程定义的流程实例,运行查询,访问活动或历史流程实例以及相关数据等等。本节将逐步介绍各种概念和
使用基于注解的映射语句时首先要做的是创建一个MyBatis映射器类。例如,假设对于一些使用情况而言,不需要整个任务数据,而只是一小部分。一个Mapper可以做到这一点,看起来如下:
public interface MyTestMapper {
@Select("SELECT ID_ as id, NAME_ as name, CREATE_TIME_ as createTime FROM ACT_RU_TASK")
List<Map<String, Object>> selectTasks();
}
必须将此映射器提供给Process Engine配置,如下所示:
...
<property name="customMybatisMappers">
<set>
<value>org.flowable.standalone.cfg.MyTestMapper</value>
</set>
</property>
...
注意这是一个接口。底层的MyBatis框架将创建一个可以在运行时使用的实例。另请注意,该方法的返回值不是键入的,而是一个映射列表(对应于具有列值的行列表)。如果需要,可以使用MyBatis映射器进行打字。
要执行上面的查询,必须使用managementService.executeCustomSql方法。这个方法需要一个CustomSqlExecution实例。这是一个隐藏引擎的内部位,否则需要使其工作的包装。
不幸的是,Java泛型使其可读性低于原来的可读性。下面的两个泛型类型是映射器类和返回类型类。但是,实际的逻辑只是调用映射器方法并返回结果(如果适用)。
CustomSqlExecution<MyTestMapper, List<Map<String, Object>>> customSqlExecution =
new AbstractCustomSqlExecution<MyTestMapper, List<Map<String, Object>>>(MyTestMapper.class) {
public List<Map<String, Object>> execute(MyTestMapper customMapper) {
return customMapper.selectTasks();
}
};
List<Map<String, Object>> results = managementService.executeCustomSql(customSqlExecution);
上面列表中的Map条目只包含id,name和create time,而不是完整的任务对象。
使用上述方法时,任何SQL都是可能的。另一个更复杂的例子:
@Select({
"SELECT task.ID_ as taskId, variable.LONG_ as variableValue FROM ACT_RU_VARIABLE variable",
"inner join ACT_RU_TASK task on variable.TASK_ID_ = task.ID_",
"where variable.NAME_ = #{variableName}"
})
List<Map<String, Object>> selectTaskWithSpecificVariable(String variableName);
使用此方法,任务表将与变量表连接。只有变量具有特定名称的地方才被保留,并返回任务ID和相应的数值。有关使用基于Annotation的映射语句的工作示例,请检查文件夹src / test / java / org / flowable / standalone / cfg /和src / test / resources中的单元测试org.flowable.standalone.cfg.CustomMybatisMapperTest和其他类和资源/组织/流动性/独立/ cfg /中
上面文章来自盘古BPM研究院:http://vue.pangubpm.com/
文章翻译提交:https://github.com/qiudaoke/flowable-userguide
了解更多文章可以关注微信公众号:
更多推荐
所有评论(0)