-
先查询出所有的记录
-
再按起始位置和页面容量取出结果
具体实现
websiteMapper
接口:
package com.junkingboy.mapper;
import com.junkingboy.bean.Student;
import com.junkingboy.bean.User;
import com.junkingboy.bean.Website;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import java.util.List;
import java.util.Map;
/**
* @description:mybatis框架测试接口,该接口定义了.xml文件操作的表用到的方法
* @data: 2021/11/2 16:35
* @author: Lucifer
*/
public interface WebsiteMapper {
/* 使用mybatis实现分页查询的功能。一开始先查询处所有的结果然后再以结果进行排序最后进行批量读取 */
List<Website> selectWebsite5(
websiteMapper.xml
:
测试类:
package com.junkingboy.mapper;
import com.junkingboy.bean.Website;
import org.apache.ibatis.annotations.Param;
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 java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @description:WebsiteMapper接口的实现类,实现了WebsiteMapper接口
* @data: 2021/11/5 17:18
* @author: Lucifer
*/
public class WebsiteMapperImpl<T> implements WebsiteMapper {
//创建表的实现类对象
Website website = new Website();
List<Website> websiteList;
InputStream is = null;
SqlSessionFactory ssf;
SqlSession ss;
Boolean openSwitch = null;
Integer changeNum = 0;
WebsiteMapper wm = null;
/*
步骤:
Io流读取配置文件
使用SqlSessionFactory接口实现类加载配置文件
使用SqlSession接口开启连接
获取WebsiteMapper接口定义的方法
执行接口当中的方法
*/
/* 获取读取配置文件的方法 */
private Boolean readProperties() {
try {
is = Resources.getResourceAsStream("xml/mybatis-config.xml");
}catch (Exception e) {
/*结束方法*/
System.out.println("找不到配置文件!");
e.printStackTrace();
return false;
}
return true;
}
/* 循环遍历打印结果方法 */
public void printResult(List<Website> website) {
for (Website site :
website) {
System.out.println(site);
}
}