flowable自定义sql查询

一、配置xml的形式

1. 编写xml文件

<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.flow.dao.mapper.SqlMapper">
	<select id="getRole" resultType="java.util.Map">
		select * from tbl_role
	</select>
</mapper>

2. 配置ProcessEngine加载xml文件

package com.flow.config;

import java.util.HashSet;
import java.util.Set;

import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FlowableConfig implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration> {

    @Override
	public void configure(SpringProcessEngineConfiguration engineConfiguration) {
        Set<String> xm = new HashSet<>();
        xm.add("mapper/SqlMapper.xml");
        engineConfiguration.setCustomMybatisXMLMappers(xm);
	}
	
}

3. 执行查询

List<Map<String, Object>> list2 = managementService.executeCommand(new Command<List<Map<String, Object>>>() {
	@Override
	public List<Map<String, Object>> execute(CommandContext commandContext) {
		return CommandContextUtil.getDbSqlSession(commandContext).selectList("com.qzt.flow.dao.mapper.SqlMapper.getRole");
        //也可不加命名空间,直接使用id
        //return CommandContextUtil.getDbSqlSession(commandContext).selectList("getRole");
	}
});

4. Mapper接口方式查询

 SqlMapper接口所在包要和xml命名空间一直

package com.flow.dao.mapper;

import java.util.List;
import java.util.Map;

public interface SqlMapper {
    List<Map<String, Object>> getRole();
}

 执行查询

List<Map<String, Object>> list2 = managementService.executeCommand(new Command<List<Map<String, Object>>>() {
	@Override
	public List<Map<String, Object>> execute(CommandContext commandContext) {
        SqlMapper sm = CommandContextUtil.getDbSqlSession(commandContext).getCustomMapper(SqlMapper.class);		
        return sm.getRole();
    }
});

 二、配置注解的方式

1. 接口Mapper

package com.flow.dao.mapper;

import java.util.List;
import java.util.Map;

public interface SqlMapper {
    @Select("select * from tbl_role")
    List<Map<String, Object>> getRole();
}

2. 配置ProcessEngine加载mapper

package.qzt.flow.config;

import java.util.HashSet;
import java.util.Set;

import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.springframework.context.annotation.Configuration;

import com.qzt.flow.dao.mapper.SqlMapper;

@Configuration
public class FlowableConfig implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration> {

    @Override
	public void configure(SpringProcessEngineConfiguration engineConfiguration) {
        Set<Class<?>> m = new HashSet<>();
        m.add(SqlMapper.class);
        engineConfiguration.setCustomMybatisMappers(m);
	}
	
}

3. 执行查询

List<Map<String, Object>> list1 =  managementService.executeCustomSql(new AbstractCustomSqlExecution<SqlMapper, List<Map<String, Object>>>(SqlMapper.class) {
	@Override
	public List<Map<String, Object>> execute(SqlMapper mapper) {
	    return mapper.getRole();
	}
});

三、传参

 xml形式的需要获取mybatis的SqlSession即可正常传参

CommandContextUtil.getDbSqlSession(commandContext).getSqlSession()

使用DbSqlSession 不管是传对象还是map都会抛出There is no getter for property named 'xxx'异常

DbSqlSession 传参,参数需要封装成对象并继承ListQueryParameterObject

public static class Param extends ListQueryParameterObject {
    private String id;
    //不用加
    /*public String getId() {
        return id;
    }*/
}

 也可以整个dao继承AbstractQuery抽象类,参考:https://blog.csdn.net/weixin_52265084/article/details/112200147

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值