栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

mybatis中oracle实现分页效果实例代码

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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 selectall(RowBounds rb);//需要传RowBounds 类型的参数

}

配置文件



 
 
  
    select * from (select t.*,rownum rownu from STUDENT t 
    where rownum<=#{param1}*#{param2})tt
    where tt.rownu>(#{param1}-1)*#{param2}
  

 

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 st=sm.selectall(offset, limit);
    for(Student tt:st){
      System.out.println(tt);
    }
  }

}

查询结果

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/146578.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号