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 ...
随机推荐
- 使用Visual Studio 2017作为Linux C++开发工具
Visual Studio 2017 微软的宇宙第一IDE Visual Studio 2017正式版出来了,地址是:https://www.visualstudio.com/vs/whatsnew/ ...
- F# 语法概览
F#和C#的语法差别 语法上,F#和C#有两个主要差别: 用缩进而非花括号分隔代码块 用空白而非逗号分隔参数 F#常见语法元素 以下是F#代码中常见的语法元素 注释 // 这是单行注释 (* 这是多行 ...
- 3402: [Usaco2009 Open]Hide and Seek 捉迷藏
3402: [Usaco2009 Open]Hide and Seek 捉迷藏 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 78 Solved: 6 ...
- Java基础之路(四)--流程控制语句
本次我们来聊一聊Java当中的循环语句. 循环语句分三种:1.for2.while3.do--while. 三种循环语句的任务是不同的,方法也是不同的.当然他们各自的流程图也是不一样的. 3.1 wh ...
- paoding-rose 了解
paoding-rose 是人人开源的基于 spring 开发的 javaEE 框架.wiki 地址: https://code.google.com/archive/p/paoding-rose/ ...
- oracle监听(lsnrctl)详解解读
(总结)Oracle监听服务lsnrctl参数及查询状态详解 lsnrctl命令常用参数详解: lsnrctlstart启动指定的监听器 stop关闭指定的监听器 status显示监听器的状态.s ...
- Delphi的Hint介绍以及用其重写气泡提示以达到好看的效果
Delphi中使用提示是如此简单,只需将欲使用Hint的控件作如下设置: ShowHint := True; Hint := ‘提示信息’; 不必写一行代码,相当方便. 但有时我们又想自己定制提示的效 ...
- windows phone 8.1开发SQlite数据库操作详解
原文出自:http://www.bcmeng.com/windows-phone-sqlite1/ 本文小梦将和大家分享WP8.1中SQlite数据库的基本操作:(最后有整个示例的源码)(希望能通过本 ...
- linux vi hjkl由来
很远原因来自历史 I was reading about vim the other day and found out why it used hjkl keys as arrow keys. Wh ...
- webService常见问题
1.普通字符串(日期形式)转换为XMLGregorianCalendar SimpleDateFormat simpleDateFormat =new SimpleDateFormat("y ...