组合查询
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;
}
作者:山丘!
-------------------------------------------
你闻讯而来,我大喜过望,我在这等你,你又在哪呢?喜欢的话加一个“关注”呗!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!