时间:2021-07-01 10:21:17 帮助过:16人阅读
配置文件
<?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="com.dao.StudentMapper"> <select id="selectall" resultType="student" > select * from student </select> </mapper>
JUnit测试
package com.util; import static org.junit.Assert.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.SqlSession; import org.junit.After; import org.junit.Before; import org.junit.Test; import com.dao.StudentMapper; import com.model.Student; public class Jtest { private SqlSession ss; private StudentMapper sm; @Before public void setUp() throws Exception { ss=SqlSessionUtil.getSqlSession(); sm=ss.getMapper(StudentMapper.class); } @After public void tearDown() throws Exception { ss.commit(); ss.close(); } @Test public void selectall() { //跳过几行 int offset = 3; //取几行 int limit = 3; RowBounds rb = new RowBounds(offset, limit); List<Student> st=sm.selectall(rb); for(Student tt:st){ System.out.println(tt); } } }
数据就取出来了
二、物理分页。
用roacle是数据库自己的分页语句分页
接口
package com.dao; import java.util.List; import java.util.Map; import org.apache.ibatis.session.RowBounds; import com.model.Student; public interface StudentMapper { /** * 分页查询 */ public List<Student> selectall(Integer offset, Integer limit ); }
配置文件
<?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="com.dao.StudentMapper"> <select id="selectall" resultType="student"> select * from (select t.*,rownum rownu from STUDENT t where rownum<=#{param1}*#{param2})tt where tt.rownu>(#{param1}-1)*#{param2} </select> </mapper>
JUnit测试
package com.util; import static org.junit.Assert.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.SqlSession; import org.junit.After; import org.junit.Before; import org.junit.Test; import com.dao.StudentMapper; import com.model.Student; public class Jtest { private SqlSession ss; private StudentMapper sm; @Before public void setUp() throws Exception { ss=SqlSessionUtil.getSqlSession(); sm=ss.getMapper(StudentMapper.class); } @After public void tearDown() throws Exception { ss.commit(); ss.close(); } @Test public void selectall() { //当前第几页 Integer offset = 2; //每页行数 Integer limit = 3; List<Student> st=sm.selectall(offset, limit); for(Student tt:st){ System.out.println(tt); } } }
查询结果
mybatis中oracle实现分页效果
标签:odi map setup 导致 查询 dao 需要 gets color