mybatis中oracle实现分页效果
首先当我们需要通过xml格式处理sql语句时,经常会用到< ,<=,>,>=等符号,但是很容易引起xml格式的错误,这样会导致后台将xml字符串转换为xml文档时报错,从而导致程序错误。
这样的问题在iBatiS中或者自定义的xml处理sql的程序中经常需要我们来处理。其实很简单,我们只需作如下替换即可避免上述的错误:
| 原符号 | < | <= | > | >= | & | ' | " |
| 替换符号 | < | <= | > | >= | & | ' | " |
————————————————————————————————————————————————————————————————————————
数据库的数据

一、逻辑分页
接口
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(RowBounds rb);//需要传RowBounds 类型的参数 }
配置文件
<?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实现分页效果的更多相关文章
- Oracle使用MyBatis中RowBounds实现分页查询
Oracle中分页查询因为存在伪列rownum,sql语句写起来较为复杂,现在介绍一种通过使用MyBatis中的RowBounds进行分页查询,非常方便. 使用MyBatis中的RowBounds进行 ...
- mybatis中Oracle分页语句的写法
最近一段时间使用oracle数据库查询分页, 用的是springboot. Oracle数据库中没有像mysql中limit的写法, 只能换其他方式写. 考虑到oracle中的ROWNUM变量, 使用 ...
- mybatis中oracle转mysql
刚来公司实习,遇到的第一个任务就是这个,简单记录一下思路过程.人菜的很,没啥参考价值. 测试时: 将现有的oracle库转为mysql: 用的Navicat自带数据传输功能,简单粗暴 出现的问题: 1 ...
- mybatis中oracle in>1000的处理
oracle数据库中,如果你使用in,然后括号对应的是一个子查询,当查询出来的结果>1000的时候就会报错. 这个是数据库的规定,我们无法改变它. 如何解决这个问题呢? 现在我看到了三种解决方式 ...
- 在mybatis中,在列表分页查询过程中造成集合属性数据丢失的问题
由于在进行多表关联分页查询时,某一个集合属性的多条数据正好位于2页的分割处,那么就会造成在前一页获取到的该集合属性的集合内部数据不全,因为其余数据被分到了第二页, 因此建议在进行集合属性的封装时,最好 ...
- mybatis中Oracle及mysql插入时自动生成主键以及返回主键
mysql的方式: 方式一: useGeneratedKeys="true" keyProperty="id" 方式二: <selectKey keyPr ...
- Mybatis中oracle如何批量insert语句
<insert id="batchInsertNoticeUser" useGeneratedKeys="false" keyProperty=" ...
- 利用ajax实现分页效果
在网页中看到的分页效果,想一下就点击分页中的内容的时候,然后调用ajax调出对应的数据,正确的显示在相应的标签内. 1.用html实现正确的样式和结构 2.采用jquery中的ajax调出数据. 需要 ...
- mybatis中的oracle和mysql分页
这段时间一直在用mybatis+spring+springMVC的框架,总结点东西吧. mybatis的oracle分页写法: <?xml version="1.0" enc ...
随机推荐
- Rabbitmq集群高可用部署详细
序言 清风万里的季节,周末本该和亲人朋友一起消遣这烂漫的花花草草,或是懒洋洋的晒个太阳听听风声鸟鸣.无奈工作使然,理想使然,我回到啦公司,敲起啦键盘,撸起啦代码,程序狗的世界一片黯然,一片黯然,愿天下 ...
- 关于label和input对齐的那些事
input文本和label对齐 默认状态下,也就是下面这样, 文字和input是居中的. <div> <label>我是中国人</label> <input ...
- 每天一个Linux命令 3
Linux grep命令详解: grep(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一 ...
- 3893: [Usaco2014 Dec]Cow Jog
3893: [Usaco2014 Dec]Cow Jog Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 174 Solved: 87[Submit] ...
- 右键打开cmd命令出错
今天想在E盘git clone一个工程项目下来,发现自己的window10上,出现了如下问题(不知道是不是是什么软件引起的冲突) 在度娘里面找了半天也没有解决问题,只有通过如下方法实现了 ctrl+r ...
- HTML+CSS-淘宝网页
<html> <head> <meta http-equiv="Content-Type" content="text/html;chars ...
- quartz任务时间调度入门使用
Quartz 是 OpenSymphony 开源组织在任务调度领域的一个开源项目,完全基于 Java 实现. 作为一个优秀的开源调度框架,Quartz 具有以下特点: 强大的调度功能,例如支持丰富多样 ...
- Linux云自动化运维第三课
Linux云自动化运维第三课 一.正则表达式 1.匹配符 * ###匹配0到任意字符 ? ###匹配单个字符 [[:alpha:]] ###匹配单个字母 [[:lower:]] ###匹配单个小写字母 ...
- 定时任务框架APScheduler学习详解
APScheduler简介 在平常的工作中几乎有一半的功能模块都需要定时任务来推动,例如项目中有一个定时统计程序,定时爬出网站的URL程序,定时检测钓鱼网站的程序等等,都涉及到了关于定时任务的问题,第 ...
- iOS开发之Run Loop
1.概述 (1) Run Loop提供了一种异步执行代码的机制,不能并行执行任务. (2) 在主队列中,Main Run Loop直接配合任务的执行,负责处理UI事件.计时器,以及其它内核相关事件. ...