Mybatis-Plus学习之简单使用Wrapper与Page(二)

Wrapper

    @Test
    public void testWrapper(){
        QueryWrapper<Cityinfo> queryWrapper=new QueryWrapper<>();
        queryWrapper
                .between("id",20,30)
                .likeLeft("cityname","山")
                ;
        QueryWrapper<Cityinfo> lambdaQueryWrapper=new QueryWrapper<>();
        lambdaQueryWrapper.lambda()
                .eq(Cityinfo::getCityname,"宝山")
                ;
        cityinfoMapper.selectList(queryWrapper).forEach(System.out::println);
        System.out.println("----------------------------------------------------------");
        cityinfoMapper.selectList(lambdaQueryWrapper).forEach(System.out::println);

    }

Page

@EnableTransactionManagement
@Configuration
public class MybatisPlusConfig{
    /**
     * 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        // 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求  默认false
        // paginationInterceptor.setOverflow(false);
        // 设置最大单页限制数量,默认 500 条,-1 不受限制
        // paginationInterceptor.setLimit(500);
        // 开启 count 的 join 优化,只针对部分 left join
        paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));
        return paginationInterceptor;
    }
}
@Test
    public void testPage(){
        //当前页
        //页面大小
        Page<Cityinfo> page = new Page<>(2,5);
        cityinfoMapper.selectPage(page,null);
        page.getRecords().forEach(System.out::println);
        System.out.println(page.getTotal());
        System.out.println(page.hasNext());
        System.out.println(page.hasPrevious());
        System.out.println(page.getCurrent());
    }

你可能感兴趣的:(笔记)