springboot + mybatis plus实现多表联查分页

1 配置分页插件

public class MybatisPlusConfig {
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
    @Bean
    public PerformanceInterceptor performanceInterceptor() {
        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
        Properties properties = new Properties();
        properties.setProperty("format", "true");
        performanceInterceptor.setProperties(properties);
        return performanceInterceptor;
    }
}

2 创建返回实体VO

@ApiModel(value = "员工得分信息")
public class AgentOutVo {
    @ApiModelProperty(value = "所在单位")
    private String unit;
    略……
    @ApiModelProperty(value = "申诉状态")
    private String appealState;
}

3 service层
接口

public interface IAgentScoreService {
    List<AgentOutVo> queryAgentOutMapByPage(Map<String, Object> params);
}

实现

public class AgentScoreServiceImpl extends ServiceImpl<AgentScoreMapper, AgentScore> implements IAgentScoreService {
    @Autowired
    private AgentScoreMapper agentScoreMapper;
    @Override
    public List<AgentOutVo> queryAgentOutMapByPage(Map<String, Object> params) {
        return agentScoreMapper.selectAgentOutMap(new Query<AgentOutVo>(params).getPage(),params);
    }
}

4 mapper

public interface AgentScoreMapper extends BaseMapper<AgentScore> {
    List<AgentOutVo> selectAgentOutMap(Page<AgentOutVo> pagination, @Param("params") Map<String, Object> params);//params 接收前端对象
}

5 resources/mapper/

<select id="selectAgentOutMap" resultType="com.itcc.qc.module.vo.AgentOutVo" parameterType="java.util.Map">
      select
      a.unit,a.dept,a.mission,a.workorder_pid,a.RECORD as recordtime,a.call, t.total_score,a.qer,t.appeal_state
      from
      t_qc_agentscore t,t_qc_agentscoreass a
      where
      t.workorder_pid=a.workorder_pid
      and
t.appeal_state=#{params.appealState} <!—对应mapper @Param("params")-->
   </select>

原文地址:https://blog.51cto.com/4534309/2377536

时间: 2024-08-07 02:27:07

springboot + mybatis plus实现多表联查分页的相关文章

mysql 两表联查分页排序效率优化

数据库中有两张表 t1 存储消息信息 +-----------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI |

SpringBoot+Mybatis 自动创建数据表(适用mysql)

Mybatis用了快两年了,在我手上的发展史大概是这样的 第一个阶段 利用Mybatis-Generator自动生成实体类.DAO接口和Mapping映射文件.那时候觉得这个特别好用,大概的过程是这样的 在数据库中先建好表配置好几个xml文件(一般都是复制粘贴上一个项目的),然后根据数据库中的表,生成实体类.DAO接口和Mapping映射文件当需要添加数据操作的时候,先在xml中写好CRUD语句,然后在DAO接口层写接口,最后到映射文件渐渐地,我忽然发现,这种方式越来越烦.改一个字段,要修改很多

mybatis.net 多表联查

mybatis.net针对多表联查,其实不用讲联查出的所有的列全部做一个新的resultMap,我们完全可以通过集成关系来实现,真是上一次说的懒加载,在一定程度上可以提高其性能,但这并不是说懒加载性能一定就差,他有其自己的用途,比如我们只需要查询主表的一条记录,但是在从表中却有1000条记录,就比较适合用懒加载. 参见http://www.cnblogs.com/zuolijun/p/5443823.html <resultMap id="teamMemberPermissionDocto

SpringBoot整合mybatis多表联查之数据库建表

1.各关联表尽量不要使用相同的字段.因为在多表联查时,如果出现相同的字段,数据库自动使这些相同字段的值相等. 比如说,订单表有一个表示订单状态的status字段,而它的外键关联的表car有一个表示车状态的status字段,这两个status表示的含义完全不一样,但因为两个status字段一样,数据库默认将他们的值相等,导致数据失真. 2.在mapper.xml文件中使用的sql语句,应先在数据库测试成功后才使用. 3.在运行整个项目之前,应先对各个mapper,service,controlle

springboot +mybatis分页插件PageHelper

1.问题描述 JAVA界ORM的两位大佬Hibernate和Mybatis,hb自带分页(上手挺快,以前用了好几年hb,后期运维及优化快疯了),mybatis没有分页功能,需要借助第三方插件来完成,比较流行的三方框架:PageHelper,今天结合springboot做下介绍,直接贴线上配置,保证可用(如有遗漏,朋友们可以指正下). 2. 解决方案 2.1 配置项目pom.xml <!--分页--> <dependency> <groupId>com.github.pa

使用mybatis多表联查的时候结果异常及springmvc的理解

今天使用mybatis多表联查的时候,在dos窗口查询时可以出结果集,但是使用mybatis查询的时候最后返回的结果只有最后一个结果 然后研究了半天没弄出来,后来无意中发现添加了最外层从表的ID字段后结果就查出来了,由此可见,数据是由主键来区分的,当主键不在查询范围时,数据默认调用最后一条语句 另外使用springmvc时无法使用实例化service对象,会报空指针异常

springboot + mybatis配置分页插件

1:首先配置springboot +mybatis框架  参考:http://www.cnblogs.com/liyafei/p/7911549.html 2:创建配置类MybatisConfig,对分页插件进行配置.将mybatis-config.xml移动到classpath路径下. package com.liyafei.util.pagehelper; import java.util.Properties; import org.apache.ibatis.plugin.Interce

MyBatis(四)关于多表联查 关联关系之一--------一对多(单条sql语句查询)

在MyBatis中,进行多表联查时关联关系主要有这几种:一对多,多对一,多对多,还有一种自关联 1.一对多:有两种方式 (1)用一条sql语句进行查询    (以查询部门和员工为案例) 首先创建实体类 package entity; import java.util.List; /** * Created by mycom on 2018/2/26. */ public class Dept {//部门 private Integer deptNo; private String deptNam

SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页

SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页 **SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了.全部自动实现. 话不多说,直接上代码: 第一步pom文件配置添加jar: <!-- mybatis的分页插件 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>