MyBatis-Plus 使用总结

MP 分页插件

配置类 MybatisPlusConfig

package mybatis.cn.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yanyg
 * @since 2020/8/19
 */
@Configuration
public class MybatisPlusConfig {
    
    

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

}

用法

@Test
public void testSelectByPage() {
    
    
    System.out.println("===========按条件查询============");
    QueryWrapper wrapper = new QueryWrapper();
    wrapper.eq("name", "七仙女");
    wrapper.orderByAsc("id");
    IPage<Persons> page = new Page<>(1, 3);
    IPage<Persons> personsIPage = personsMapper.selectPage(page, wrapper);
    personsIPage.getRecords().forEach(System.out::println);
    System.out.println("当前分页总页数===>" + personsIPage.getPages());
    System.out.println("总条数===>" + personsIPage.getTotal());
}

猜你喜欢

转载自blog.csdn.net/thebigdipperbdx/article/details/108096314