十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
在mybatis項目中使用oracle如何實現(xiàn)一個分頁效果?相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。
創(chuàng)新互聯(lián)公司專注于肅北網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供肅北營銷型網(wǎng)站建設(shè),肅北網(wǎng)站制作、肅北網(wǎng)頁設(shè)計、肅北網(wǎng)站官網(wǎng)定制、小程序制作服務(wù),打造肅北網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供肅北網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
首先當(dāng)我們需要通過xml格式處理sql語句時,經(jīng)常會用到< ,<=,>,>=等符號,但是很容易引起xml格式的錯誤,這樣會導(dǎo)致后臺將xml字符串轉(zhuǎn)換為xml文檔時報錯,從而導(dǎo)致程序錯誤。
這樣的問題在iBatiS中或者自定義的xml處理sql的程序中經(jīng)常需要我們來處理。其實很簡單,我們只需作如下替換即可避免上述的錯誤:
原符號 | < | <= | > | >= | & | ' | " |
替換符號 | < | <= | > | >= | & | ' | " |
數(shù)據(jù)庫的數(shù)據(jù)
一、邏輯分頁
接口
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 Listselectall(RowBounds rb);//需要傳RowBounds 類型的參數(shù) }
配置文件
<?xml version="1.0" encoding="UTF-8"?>
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); Listst=sm.selectall(rb); for(Student tt:st){ System.out.println(tt); } } }
數(shù)據(jù)就取出來了
二、物理分頁。
用roacle是數(shù)據(jù)庫自己的分頁語句分頁
接口
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 Listselectall(Integer offset, Integer limit ); }
配置文件
<?xml version="1.0" encoding="UTF-8"?>
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() { //當(dāng)前第幾頁 Integer offset = 2; //每頁行數(shù) Integer limit = 3; Listst=sm.selectall(offset, limit); for(Student tt:st){ System.out.println(tt); } } }
查詢結(jié)果
看完上述內(nèi)容,你們掌握在mybatis項目中使用oracle如何實現(xiàn)一個分頁效果的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!