欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

mybatis中oracle實(shí)現(xiàn)分頁(yè)效果實(shí)例代碼

 更新時(shí)間:2017年04月24日 11:22:47   作者:濫好人  
實(shí)現(xiàn)分頁(yè)的方式有很多,但常用的是通過(guò)SQL來(lái)顯示分頁(yè)。這篇文章主要介紹了mybatis中oracle實(shí)現(xiàn)分頁(yè)效果實(shí)例代碼,有興趣的可以了解一下。

首先當(dāng)我們需要通過(guò)xml格式處理sql語(yǔ)句時(shí),經(jīng)常會(huì)用到< ,<=,>,>=等符號(hào),但是很容易引起xml格式的錯(cuò)誤,這樣會(huì)導(dǎo)致后臺(tái)將xml字符串轉(zhuǎn)換為xml文檔時(shí)報(bào)錯(cuò),從而導(dǎo)致程序錯(cuò)誤。

這樣的問(wèn)題在iBatiS中或者自定義的xml處理sql的程序中經(jīng)常需要我們來(lái)處理。其實(shí)很簡(jiǎn)單,我們只需作如下替換即可避免上述的錯(cuò)誤:

原符號(hào)  <  <=   > >=   &   '   "
替換符號(hào) &lt; &lt;= &gt; &gt;= &amp; &apos; &quot;

數(shù)據(jù)庫(kù)的數(shù)據(jù)

一、邏輯分頁(yè)

接口

package com.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;

import com.model.Student;

public interface StudentMapper {
  /**
   * 分頁(yè)查詢(xún)
   */
  public List<Student> selectall(RowBounds rb);//需要傳RowBounds 類(lèi)型的參數(shù)

}

配置文件

<?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測(cè)試

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() {
    
    //跳過(guò)幾行
    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);
    }
  }

}

數(shù)據(jù)就取出來(lái)了

二、物理分頁(yè)。

用roacle是數(shù)據(jù)庫(kù)自己的分頁(yè)語(yǔ)句分頁(yè)

 

接口

package com.dao;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;

import com.model.Student;

public interface StudentMapper {
  
  /**
   * 分頁(yè)查詢(xún)
   */
  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&lt;=#{param1}*#{param2})tt
    where tt.rownu>(#{param1}-1)*#{param2}
  </select>

 </mapper>

JUnit測(cè)試

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() {
    //當(dāng)前第幾頁(yè) 
    Integer offset = 2;
    //每頁(yè)行數(shù)
    Integer limit = 3;    
    List<Student> st=sm.selectall(offset, limit);
    for(Student tt:st){
      System.out.println(tt);
    }
  }

}

查詢(xún)結(jié)果

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java中的Pair詳細(xì)

    Java中的Pair詳細(xì)

    這篇文章主要介紹Java中的很有意思的Pair,下面文章會(huì)以Pair用法展開(kāi),感興趣的小伙伴可以參考下面文章的具體內(nèi)容
    2021-10-10
  • java生成pdf表格,調(diào)用itext創(chuàng)建的實(shí)例

    java生成pdf表格,調(diào)用itext創(chuàng)建的實(shí)例

    這篇文章主要介紹了java生成pdf表格,調(diào)用itext創(chuàng)建的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-01-01
  • SpringBoot?Application核心注解詳解

    SpringBoot?Application核心注解詳解

    進(jìn)入到@SpringBootApplication的源碼,可以看到里面組合了三個(gè)我們感興趣的注解@ComponentScan、@EnableAutoConfiguration、@SpringBootConfiguration,我們一一分析這三個(gè)注解
    2022-10-10
  • Springboot整合hibernate validator 全局異常處理步驟詳解

    Springboot整合hibernate validator 全局異常處理步驟詳解

    本文分步驟給大家介紹Springboot整合hibernate validator 全局異常處理,補(bǔ)呢文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2024-01-01
  • Java的Junit測(cè)試框架中的其他注解說(shuō)明

    Java的Junit測(cè)試框架中的其他注解說(shuō)明

    這篇文章主要介紹了Java的Junit測(cè)試框架中的其他注解說(shuō)明,JUnit是一個(gè)開(kāi)源的java單元測(cè)試框架,它是XUnit測(cè)試體系架架構(gòu)的一種體現(xiàn),
    是Java語(yǔ)言事實(shí)上的標(biāo)準(zhǔn)單元測(cè)試庫(kù),需要的朋友可以參考下
    2023-10-10
  • SpringBoot數(shù)據(jù)庫(kù)初始化datasource配置方式

    SpringBoot數(shù)據(jù)庫(kù)初始化datasource配置方式

    這篇文章主要為大家介紹了SpringBoot數(shù)據(jù)庫(kù)初始化datasource配置方式,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • 詳解maven配置多倉(cāng)庫(kù)的方法示例

    詳解maven配置多倉(cāng)庫(kù)的方法示例

    這篇文章主要介紹了詳解maven配置多倉(cāng)庫(kù)的方法示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • 聊聊Controller中RequestMapping的作用

    聊聊Controller中RequestMapping的作用

    這篇文章主要介紹了Controller中RequestMapping的作用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-02-02
  • idea web項(xiàng)目沒(méi)有小藍(lán)點(diǎn)的的兩種解決方法

    idea web項(xiàng)目沒(méi)有小藍(lán)點(diǎn)的的兩種解決方法

    本文主要介紹了idea web項(xiàng)目沒(méi)有小藍(lán)點(diǎn)的的兩種解決方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • idea 創(chuàng)建properties配置文件的步驟

    idea 創(chuàng)建properties配置文件的步驟

    這篇文章主要介紹了idea 創(chuàng)建properties配置文件的步驟,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-01-01

最新評(píng)論