zoukankan      html  css  js  c++  java
  • 如何自定义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);

     

      

      

      

      

  • 相关阅读:
    移除TDE
    SQL Server 聚集索引和非聚集索引的区别
    Serivce Broker 简单实用
    SQL Server 2012 ColumnStore索引测试
    UISegmentedControl的所有操作总结
    iPhone开发之深入浅出 — ARC之前世今生(三)
    什么是 ARC?ios5,xcode 4.2
    Present ViewController详解
    UITextField的总结
    iPhone开发资料之内存管理 ,循环引用导致的内存问题
  • 原文地址:https://www.cnblogs.com/liuwenjun/p/11471536.html
Copyright © 2011-2022 走看看