物理分页 : 通过SQL语句在数据库中直接分页拿数据(多次在数据库中拿数据,耗性能)
逻辑分页 :先将数据拿出来,再将数据进行逻辑分页 (可能会因为数据量过大,导致内存溢出)
而MyBatis 原生态 默认是使用了逻辑分页!如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="lesson1_pagehelper.ActionSQL">
<select id="query" resultType="lesson1_pagehelper.StuBean">
SELECT * FROM student
</select>
</mapper>
在xml中选中sql查询的是所有
package lesson1_pagehelper;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
public class ActionSQLShow {
public static SqlSession getSession() {
String resource = "config.xml";
InputStream inputStream = ActionSQLShow.class.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
SqlSession openSession = sqlSessionFactory.openSession();
return openSession;
}
@Test
public void text() {
List<StuBean> selectList = getSession().selectList("lesson1_pagehelper.ActionSQL.query",
null,new RowBounds(10,10));
System.out.println(selectList.size());
}
}
但是查询的结果为10条 RRowBounds(int offset, int limit)有两个参数 offset开始查询的条数 ,limit查询多少条;