mybatis中oracle实现分页效果
来源:互联网 发布:单片机小车轮子掉 编辑:程序博客网 时间:2024/04/28 18:51
首先当我们需要通过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); } }}
查询结果
0 0
- mybatis中oracle实现分页效果
- MyBatis分页实现 - Oracle
- Mybatis-实现ORACLE分页查询
- bootstrap + mybatis + maven + springmvc 实现分页效果
- cocos2dx 中实现分页效果
- Cocos2dx中实现分页效果
- MyBatis分页实现 - Oracle(二)
- Spring +Mybatis +oracle 实现数据库分页
- Mybatis+Oracle实现按条件分页查询
- SpringMVC+Mybatis+Oracle实现web分页
- Mybatis+Oracle实现按条件分页查询
- MyBatis学习(八)- MyBatis分页实现 - Oracle
- MyBatis学习(九)-MyBatis分页实现 - Oracle(二)
- mybatis中使用SqlBuilder实现分页
- SqlServer中使用游标实现分页效果
- 在java页面中实现分页效果
- jsp页面中实现分页效果
- oracle+mybatis分页查询
- OVER(PARTITION BY)函数介绍
- html5的canvas绘制迷宫地图
- PHP跨域 解决跨域
- 算法的时间复杂度和空间复杂度-总结
- 【GDOI2017第四轮模拟day2】叶片
- mybatis中oracle实现分页效果
- 空接口是什么?
- 国际RFX流程
- ReentrantLock(一):谈谈ReentrantLock与synchronized
- bzoj 4154: [Ipsc2015]Generating Synergy KDtree
- 速度中企 激情动力
- [PlantSimulation]Resources应用
- matplotlib画X轴时间的显示问题
- 数据库重组函数:call sysproc.admin_cmd('reorg table TABLE_NAME');