mybatis 逆向 or和order by的用法 分页查询见挨着的上一篇文章

github源码

https://github.com/hanpenghu/beetltest.git

package com.hanhan.Test;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hanhan.dao.SysUserMapper;
import com.hanhan.entity.SysUser;
import com.hanhan.entity.SysUserExample;
import hanhan.pp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class TestPageHelper {
    private org.slf4j.Logger log= org.slf4j.LoggerFactory.getLogger(this.getClass());
    @Autowired
    private SysUserMapper sysUserMapper;



    @Scheduled(fixedDelay = Long.MAX_VALUE,initialDelay = 10000)
    public void f1(){
        //        //2、设置分页,第一个参数是当前页页码,第二个参数是每页显示数
        PageHelper.startPage(1, 4);
        //3、执行查询
        SysUserExample example = new SysUserExample();
        example.setOrderByClause("CREATE_TIME ASC");
        example.createCriteria().andIdEqualTo("abc");
        example.or().andIdEqualTo("abc1");
        List<SysUser> list = sysUserMapper.selectByExample(example);
        //4、取分页后结果
        PageInfo<SysUser> pageInfo = new PageInfo<>(list);
        //得到总记录数
        long total = pageInfo.getTotal();
        //打印总记录数
        pp.logInfo(log,"total:打印总记录数",total);
        //得到总页数
        int pages = pageInfo.getPages();
        //打印总页数
        pp.logInfo(log,"pages 总页数:",pages);
        //打印传给前端的实体
        pp.logInfo(log,"pageInfo.getList() 打印传给前端的实体",pageInfo.getList());


    }



  /*  @Scheduled(fixedDelay = Long.MAX_VALUE,initialDelay = 10000)
    public void f2(){
        SysUserExample sysUserExample=new SysUserExample();
        sysUserExample.createCriteria().andIdIsNotNull();
        List<SysUser> sysUsers = sysUserMapper.selectByExample(sysUserExample);
        log.info("@@@@@@sysUsers={}@@@@@@@@",sysUsers);
    }*/








}

猜你喜欢

转载自blog.csdn.net/hanpenghu/article/details/84257956