flowable交流群:633168411

如何自定义sql

场景: 在实际项目中,有可能你会自己写一些sql,但是你又不想写过多的dao,service xml的时候,我们可以利用flowable自身的自定义sql实现

实现这一场景,我们一般有两种方式。

1、配置xml的形式

1.1、编写xml文件

1.2、配置config

 
<property name="customMybatisXMLMappers">
        <set>
            <value>org/flowable/standalone/cfg/custom-mappers/CustomTaskMapper.xml</value>
        </set>
    </property>

 

1.3、执行查询操作

 
CustomTask customTask = managementService.executeCommand(new Command<CustomTask>() {
            @Override
            public CustomTask execute(CommandContext commandContext) {
                return (CustomTask) CommandContextUtil.getDbSqlSession(commandContext).selectOne("selectOneCustomTask", taskId);
            }
        });

 

2、注解的方式

2.1、配置查询接口注解

 
public interface MyTestMapper {

    @Select("SELECT ID_ as id, NAME_ as name, CREATE_TIME_ as createTime FROM ACT_RU_TASK")
    List<Map<String, Object>> selectTasks();

    @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);

}

 

2.2、配置config

 
<property name="customMybatisMappers">
        <set>
            <value>org.flowable.standalone.cfg.MyTestMapper</value>
        </set>
    </property>

 

2.3、执行sql

 

 

 // Fetch the columns we're interested in
        CustomSqlExecution<MyTestMapper, List<Map<String, Object>>> customSqlExecution = new AbstractCustomSqlExecution<MyTestMapper, List<Map<String, Object>>>(MyTestMapper.class) {

            @Override
            public List<Map<String, Object>> execute(MyTestMapper customMapper) {
                return customMapper.selectTasks();
            }
        };

        // Verify
        List<Map<String, Object>> tasks = managementService.executeCustomSql(customSqlExecution);

 

 

  

  

  

  

posted @ 2019-09-06 10:49  小学生05101  阅读(1608)  评论(0编辑  收藏  举报
flowable交流群:633168411