Mybitis-Plus自定义分页

添加maven依赖

<dependency>
	<groupId>com.baomidou</groupId>
	<artifactId>mybatis-plus-boot-starter</artifactId>
	<version>3.1.0</version>
</dependency>

properties

mybatis-plus.typeAliasesPackage=com.gx.domain
mybatis-plus.mapper-locations=classpath:/mapper/*Mapper.xml

添加分页插件

@Configuration
@EnableTransactionManagement
public class MyBatisPlusConfig {

    /**
     * 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    /**
     * 打印 sql
     */
    @Bean
    public PerformanceInterceptor performanceInterceptor() {
        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
        //格式化sql语句
        Properties properties = new Properties();
        properties.setProperty("format", "true");
        performanceInterceptor.setProperties(properties);
        return performanceInterceptor;
    }
}

编写mapper接口

public interface TravelPointMapper extends BaseMapper<TravelPoint> {

    IPage<TravelPoint> selectTravePonintPage(IPage<TravelPoint> pagination, @Param("dto") QueryTravePointPageDTO queryTravePointPageDTO);

}

mapper文件

<?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.gx.mapper.TravelPointMapper">

    <select id="selectTravePonintPage" resultType="com.gx.domain.TravelPoint">
        select
            stp.*, sp.thumb
        from
            sent_travel_point stp
        left join
            sent_picture sp
        on
            stp.logo = sp.id
        where
            stp.status = 1
            <if test="dto.type != null and dto.type != ''">
                and stp.type = #{dto.type}
            </if>
        order by
            stp.sort
    </select>
</mapper>

调用Mapper接口

Page<TravelPoint> page = new Page<>();
page.setSize(queryTravePointPageDTO.getSize());
page.setCurrent(queryTravePointPageDTO.getCurrent());
IPage<TravelPoint> travelPointIPage = travelPointMapper.selectTravePonintPage(page, queryTravePointPageDTO);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值