flowable 如何自定义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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小学生05101

flowable

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值