zoukankan      html  css  js  c++  java
  • 组合查询

    Mybaits-plus 中,两张表组合查询,xml方式


    在FlowMapper接口中自定义接口

    public interface FlowMapper extends BaseMapper<Flow> {
        List<Flow> pageList(FlowDTO dto);
    }
    

    手动添加FlowMapper.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.ruoyi.project.dy.mapper.FlowMapper">
    
        <resultMap id="resultMap" type="com.ruoyi.project.dy.domain.Flow">
            <id property="flowId" column="flow_id"/>
            <result property="flowName" column="flow_name"/>
            <result property="cyclicTimes" column="cyclic_times"/>
            <result property="status" column="status"/>
            <result property="createBy" column="create_by"/>
            <result property="createTime" column="create_time"/>
            <result property="updateBy" column="update_by"/>
            <result property="updateTime" column="update_time"/>
        </resultMap>
    
        <select id="pageList" parameterType="FlowDTO" resultMap="resultMap">
            select f.*
            from t_flow f
            left join t_flow_bind fb on f.flow_id=fb.flow_id
            <where>
                <if test="flowName !=null and flowName != ''">
                    and f.flow_name = #{flowName}
                </if>
                <if test="productTno !=null and productTno != '' ">
                    and fb.product_tno = #{productTno}
                </if>
                <if test="scheduleStage !=null and scheduleStage != '' ">
                    and fb.schedule_stage = #{scheduleStage}
                </if>
                <if test="flowStatus !=null">
                    and f.status = #{flowStatus}
                </if>
            </where>
        </select>
    </mapper>
    

    修改namespace,并且自定义传入参数类型

    package com.ruoyi.project.dy.domain.dto;
    
    import lombok.Data;
    
    /**
     * @author LIAO
     */
    @Data
    public class FlowDTO {
        /**
         * 流程名称
         */
        private String flowName;
        /**
         * 图号
         */
        private String productTno;
        /**
         * 阶段编号
         */
        private String scheduleStage;
        /**
         * 流程状态
         */
        private String flowStatus;
    }
    

    然后在service和service实现类中进行实现

    /**
     * 流程列表
     *
     * @param dto 条件查询
     * @return
     */
    List<Flow> pageList(FlowDTO dto);
    
    
     @Override
       public List<Flow> pageList(FlowDTO dto) {
    		return baseMapper.pageList(dto);
       }
    

    最后在cnotroller中进行调用,注意使用若依分页的时候,startPage()写在需要分页查询的前面,手动获取分页的结果,getDataTable(),并自定义返回结果

    @GetMapping("/list")
    public TableDataInfo list(FlowDTO dto) {
    
        //默认状态 0 正常 没用注销状态
        String flowStatus = "0";
    
        dto.setFlowStatus(flowStatus);
    
    
        //条件查询
        startPage();
        List<Flow> flowList = flowService.pageList(dto);
    
        // List<Flow> flowList = flowService.list(Wrappers.<Flow>query().lambda().eq(Flow::getStatus, flowStatus));
    
        // 用于流程管理页面展示
        TableDataInfo dataTable = getDataTable(flowList);
    
        List<FlowIndexVo> list = new ArrayList<>();
    
        // 根据流程id遍历流程和图号绑定表
        for (Flow f : (List<Flow>) dataTable.getRows()) {
            FlowIndexVo flowIndexVo = new FlowIndexVo();
            String flowId = f.getFlowId();
            flowIndexVo.setFlowId(flowId);
            flowIndexVo.setFlowName(f.getFlowName());
            flowIndexVo.setUpdateTime(f.getUpdateTime());
            List<FlowBind> flowBinds = flowBindService
                    .list(Wrappers.<FlowBind>query().lambda().eq(FlowBind::getFlowId, flowId));
            flowIndexVo.setFlowBindList(flowBinds);
            list.add(flowIndexVo);
        }
    
        dataTable.setRows(list);
        return dataTable;
    }
    
    作者:山丘!

    -------------------------------------------

    你闻讯而来,我大喜过望,我在这等你,你又在哪呢?喜欢的话加一个“关注”呗!

    如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!

  • 相关阅读:
    [PHP] Which function can be used to format a local timestamp according to a specific locale?
    [Yii Framework] yii 如何使用第三方插件
    [PHP] Header to out put the image file.
    [PHP] PHP 格式化日期 format the datetime in PHP
    VC6工程中的文件类型
    VC6++ output :error executing c:\windows\system32\cmd.exe.
    根据选择计算Mask值
    .NET垃圾收集关键方法解析(转)
    JS访问表格的每行的每个TD的方法
    HTTP 状态消息详解
  • 原文地址:https://www.cnblogs.com/mengd/p/15141054.html
Copyright © 2011-2022 走看看