1.使用 中央仓库查找热门版本:仓库地址
1.1 引入依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis.plus.version}</version>
</dependency>
1.2 分页插件配置
package com.example.config;
import com.baomidou.mybatisplus.extension.incrementer.OracleKeyGenerator;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Properties;
@Configuration
public class MybatisPlusConfig {
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor page = new PaginationInterceptor();
Properties prop=new Properties();
prop.setProperty("dialectType","oracle");
prop.setProperty("overflow","true");
page.setProperties(prop);
return page;
}
@Bean
public OracleKeyGenerator oracleKeyGenerator() {
return new OracleKeyGenerator();
}
}
1.3 mapper继承com.baomidou.mybatisplus.core.mapper.BaseMapper<>,泛型是数据库表映射dto,page参数必须带上
public interface GeneralMapper extends BaseMapper<GeneralDto> {
List<GeneralVo> page(com.baomidou.mybatisplus.core.metadata.IPage<GeneralVo> page, @Param("dto") GeneralDto dto);
}
1.4 xml书写查询全量的sql
<select id="page"
parameterType="*.GeneralDto"
resultType="*.GeneralVo">
select *
from
General
where
DELETED=0
<if test="dto.activated != null and dto.activated != ''">
and ACTIVATED = #{dto.activated}
</if>
order by UPDATEDATE desc
</select>
2.分析 分页插件分页原理: a:PaginationInterceptor对象那个初始化,指定数据库方言,在spring容器注册一个paginationInterceptor的bean; b:paginationInterceptor拦截sql查询准备阶段,通过方言确定数据库类型,返回对应数据库sql组装方式 c:通过page参数,替换占位符得到最终查询sql d:根据最终得到的sql查询数据库 2.1 相关代码 a: b:
|