• 如何自定义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);

     

      

      

      

      

  • 相关阅读:
    套接字和域名系统DNS
    TCP滑动窗口控制流量的原理
    AngularJS 路由
    使用纯前端JavaScript 实现Excel IO
    Deferred在jQuery和Angular中的使用与简单实现
    深入理解函数声明和函数表达式(转)
    Visual Studio Code 智能提示文件
    JavaScript框架设计(四) 字符串选择器(选择器模块结束)
    JavaScript框架设计(三) push兼容性和选择器上下文
    canvas学习和面向对象(二)
  • 原文地址:https://www.cnblogs.com/liuwenjun/p/11471536.html
Copyright © 2020-2023  润新知