27.flowable 自定义sql查询

本文介绍如何在Flowable流程引擎中使用自定义SQL查询,通过定义mapper接口、配置mapper、创建service及测试方法,实现对流程实例评论的个性化查询。

项目地址:https://gitee.com/lwj/flowable.git 分支flowable-base
视频地址:https://www.bilibili.com/video/av79774697/
业务场景:在实际开发中,由于我们需要一些flowable的个性化查询,而且他们提供的api无法满足我的需求的时候,这个时候我们应该考虑flowable有没有那种自定义的sql方式,其实flowable已经给我们预留了这样的接口方便我们随意扩展。
这里我就讲一种注解的方式扩展自定义sql查询

1、首先我们要定义一个mapper接口
public interface CustomCommentMapper {

    @Select({ "select t.* from act_hi_comment t where t.PROC_INST_ID_ = #{procInstId}" })
    List<Map<String, Object>> selectCommentsByProcInstId(String procInstId);
}
2、配置mapper到config里面
//自定义sql
        Set<Class<?>> customMybatisMappers = new HashSet<>();
        customMybatisMappers.add(CustomCommentMapper.class);
        configure.setCustomMybatisMappers(customMybatisMappers);
3、定义service
@Service
public class CustomCommentService {

    @Autowired
    private ManagementService managementService;

    public List<Map<String, Object>> getCommentsByProcInstId(String procInstId) {
        CustomSqlExecution<CustomCommentMapper, List<Map<String, Object>>> customSqlExecution = new AbstractCustomSqlExecution<CustomCommentMapper, List<Map<String, Object>>>(CustomCommentMapper.class) {
            @Override
            public List<Map<String, Object>> execute(CustomCommentMapper customMapper) {
                return customMapper.selectCommentsByProcInstId(procInstId);
            }
        };
        return managementService.executeCustomSql(customSqlExecution);
    }
}
4、测试
 @Test
    public void testXml() {
        List<Map<String, Object>> comments = customCommentService.getCommentsByProcInstId("aa798e711a9a11eaa07cdc8b287b3603");
        System.out.println(comments);
    }
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'processEngine': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:176) at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:101) at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1828) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1265) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:334) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788) ... 84 common frames omitted Caused by: java.lang.NullPointerException: null at org.flowable.engine.impl.db.ProcessDbSchemaManager.schemaUpdate(ProcessDbSchemaManager.java:232) at org.flowable.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:54) at org.flowable.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:28) at org.flowable.engine.impl.interceptor.CommandInvoker$1.run(CommandInvoker.java:67) at org.flowable.engine.impl.interceptor.CommandInvoker.executeOperation(CommandInvoker.java:140) at org.flowable.engine.impl.interceptor.CommandInvoker.executeOperations(CommandInvoker.java:114) at org.flowable.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:72) at org.flowable.engine.impl.interceptor.BpmnOverrideContextInterceptor.execute(BpmnOverrideContextInterceptor.java:26) at org.flowable.common.engine.impl.interceptor.TransactionContextInterceptor.execute(TransactionContextInterceptor.java:53) at org.flowable.common.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:105) at org.flowable.common.spring.SpringTransactionInterceptor.lambda$execute$0(SpringTransactionInterceptor.java:57) at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) at org.flowable.common.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:57) at org.flowable.common.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30) at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56) at org.flowable.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:83) at org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:917) at org.flowable.spring.SpringProcessEngineConfiguration.buildProcessEngine(SpringProcessEngineConfiguration.java:76) at org.flowable.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:59) at org.flowable.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:32) at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:169) ... 94 common frames omitted Disconnected from the target VM, address: '127.0.0.1:63966', transport: 'socket'
最新发布
09-04
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小学生05101

flowable

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

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

打赏作者

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

抵扣说明:

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

余额充值