Mybatis-Pulus的Page、IPage分页使用

同样PageHelper也可以用
PageHelper


@Configuration
@MapperScan("startDemo.mapper")
public class MybatisPlusConfig {

    /**
     * 新的分页插件,一缓和二缓遵循mybatis的规则
     * ,需要设置
     * MybatisConfiguration#useDeprecatedExecutor = false
     * 避免缓存出现问题(该属性会在旧插件移除后一同移除)
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
        return interceptor;
    }

//    @Bean
//    public ConfigurationCustomizer configurationCustomizer() {
//        return configuration -> configuration.setUseDeprecatedExecutor(false);
//    }
}
添加依赖
        <!-- MyBatisX插件 -->
              <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.1</version>
        </dependency>
Controller层实例

    @RequestMapping("/findMember")
    public Result<?> findMember(@RequestParam(defaultValue = "1") Integer pageNum,
                                @RequestParam(defaultValue = "10") Integer pageSize){

        IPage<Member> ipage= memberService.findMember
                        (new Page<Member>(pageNum,pageSize), null);
        return Result.success(ipage);
		//调用的Mapper返回值也是Ipage<实体类>
		//IPage<Member> findMember(Page<?> page, Integer state);
    }

Mapper层需要继承BaseMapper

@Mapper
public interface CylindersMapper extends BaseMapper {

    @Select("SELECT * FROM gas_bottle ORDER BY end_time  DESC")
    public List<Gas_bottle> selectAll();

    @Select("SELECT * FROM cylinder")
    IPage<Cylinder> getAllCylinders(Page<Cylinder> page, String state);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值