import com.github.pagehelper.PageHelper;
import com.mapper.AccountMapper;
import com.mapper.DepartmentMapper;
import com.pojo.entity.AccountRealEntity;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class TestMybatisPage {
    SqlSession sqlSession;
    AccountMapper accountMapper;
    @Before
    public void before() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatisConfig.xml");
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsStream);
        sqlSession = build.openSession(true);
        accountMapper = sqlSession.getMapper(AccountMapper.class);
    }

    @Test
    public void page1() {
        // 查询分页功能 在查询列表之前先开启分页
        PageHelper.startPage(2,2);
        List<AccountRealEntity> byDepId = accountMapper.findByDepId(1);
        byDepId.forEach(System.out::println);
    }
}
