springmvc+mybatis 做分頁sql 語句實(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="ssmy.dao.UserDao">
<resultMap type="ssmy.dto.User" id="User">
<!--<resultMap type="User" id="User"> 如果在sprin文件里配置初始化 mybatis里配置了別名就是有-->
<!-- 用id屬性來映射主鍵字段 -->
<id property="id" column="id" jdbcType="INTEGER"/>
<!-- 用result屬性來映射非主鍵字段 -->
<result property="userName" column="userName" jdbcType="VARCHAR"/>
<result property="password" column="password" jdbcType="VARCHAR"/>
<result property="trueName" column="trueName" jdbcType="VARCHAR"/>
<result property="email" column="email" jdbcType="VARCHAR"/>
<result property="phone" column="phone" jdbcType="VARCHAR"/>
<result property="roleName" column="roleName" jdbcType="VARCHAR"/>
</resultMap>
<!--分頁返回類型list 可以使用map User對(duì)應(yīng)的是resultMap size每頁的大小-->
<select id="find" resultMap="User" parameterType="Map">
select t2.* from
( select t1.*,rownum rn from t_user t1
<where>
<if test ="userName !=null and userName !='' ">
t1.userName like '%'||#{userName,jdbcType=VARCHAR}||'%'
</if>
</where>
) t2
<where>
<if test ="start !=null and start !=''">
<![CDATA[and t2.rn >=#{start}]]>
</if>
<if test ="size !=null and size !=''">
and <![CDATA[t2.rn <=#{size}]]>
</if>
</where>
</select>
<!--獲取總記錄數(shù) -->
<select id="getTotal" parameterType="Map" resultType="java.lang.Integer">
select count(1) from t_user
<where>
<if test ="userName !=null and userName !='' ">
userName like '%'||#{userName,jdbcType=VARCHAR}||'%'
</if>
</where>
</select>
<!--<insert id="createser" parameterType="User">
insert into NEWS_USER (id,username,password,email,usertype)
values (#{id,jdbcType=NUMERIC},#{username,jdbcType=VARCHAR},
#{password,jdbcType=VARCHAR},#{email,jdbcType=VARCHAR},1)
<selectKey resultType="int" order="BEFORE" keyProperty="id">
select seq_id.nextval from dual
</selectKey>
</insert>-->
</mapper>
以上所述是小編給大家介紹的springmvc+mybatis 做分頁sql 語句實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!
- SpringMVC+Mybatis實(shí)現(xiàn)的Mysql分頁數(shù)據(jù)查詢的示例
- SpringMVC4 + MyBatis3 + SQL Server 2014整合教程(含增刪改查分頁)
- AJAX +SpringMVC 實(shí)現(xiàn)bootstrap模態(tài)框的分頁查詢功能
- springmvc4+hibernate4分頁查詢功能實(shí)現(xiàn)
- springmvc 分頁查詢的簡(jiǎn)單實(shí)現(xiàn)示例代碼
- SpringMvc+Mybatis+Pagehelper分頁詳解
- SpringMVC+MyBatis分頁(最新)
- 基于SpringMVC+Bootstrap+DataTables實(shí)現(xiàn)表格服務(wù)端分頁、模糊查詢
- Java簡(jiǎn)單實(shí)現(xiàn)SpringMVC+MyBatis分頁插件
- Springmvc應(yīng)用Mongodb分頁實(shí)現(xiàn)
相關(guān)文章
對(duì)象存儲(chǔ)服務(wù)MinIO快速入門(集成項(xiàng)目的詳細(xì)過程)
MinIO是一個(gè)開源的對(duì)象存儲(chǔ)服務(wù),支持多種操作系統(tǒng),配置簡(jiǎn)單且性能高,它使用糾刪碼進(jìn)行數(shù)據(jù)保護(hù),可以容忍硬件故障,MinIO支持多種語言的SDK和豐富的API,本文介紹對(duì)象存儲(chǔ)服務(wù)MinIO快速入門,感興趣的朋友一起看看吧2025-03-03
springboot application.yml使用@@pom文件配置問題
這篇文章主要介紹了springboot application.yml使用@@pom文件配置問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07
java中Class類的基礎(chǔ)知識(shí)點(diǎn)及實(shí)例
在本篇文章里小編給大家分享了關(guān)于java中Class類的基礎(chǔ)知識(shí)點(diǎn)及實(shí)例內(nèi)容,有興趣的朋友們可以學(xué)習(xí)下。2021-05-05
spring-boot整合Micrometer+Prometheus的詳細(xì)過程
這篇文章主要介紹了springboot整合Micrometer+Prometheus的詳細(xì)過程,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2024-05-05
RxJava中多種場(chǎng)景的實(shí)現(xiàn)總結(jié)
這篇文章給大家詳細(xì)介紹了RxJava中多種場(chǎng)景的實(shí)現(xiàn),對(duì)大家學(xué)習(xí)使用RxJava具有一定的參考借鑒價(jià)值,有需要的朋友們可以參考學(xué)習(xí),下面來一起看看吧。2016-10-10
java設(shè)計(jì)模式之簡(jiǎn)單工廠模式詳解
這篇文章主要介紹了java設(shè)計(jì)模式之簡(jiǎn)單工廠模式的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-09-09
SpringBoot整合SpringBoot-Admin實(shí)現(xiàn)監(jiān)控應(yīng)用功能
本文主要介紹如何整合Spring Boot Admin,以此監(jiān)控Springboot應(yīng)用,文中有相關(guān)的示例代碼供大家參考,需要的朋友可以參考下2023-05-05
springboot新建項(xiàng)目pom.xml文件第一行報(bào)錯(cuò)的解決
這篇文章主要介紹了springboot新建項(xiàng)目pom.xml文件第一行報(bào)錯(cuò)的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-01-01

