午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術文章
文章詳情頁

MyBatis limit分頁設置的實現

瀏覽:133日期:2023-10-19 14:30:10
錯誤的寫法:

<select parameterType='MyApplicationRequest' resultMap='myApplicationMap'> SELECT a.*, FROM tb_user a WHERE 1=1 <if test='ids != null and ids.size()!=0'> AND a.id IN <foreach collection='ids' item='id' index='index' open='(' close=')' separator=','> #{id} </foreach> </if> <if test='statusList != null and statusList.size()!=0'> AND a.status IN <foreach collection='statusList' item='status' index='index' open='(' close=')' separator=','> #{status} </foreach> </if> ORDER BY a.create_time desc LIMIT (#{pageNo}-1)*#{pageSize},#{pageSize}; // 錯誤</select>

在MyBatis中LIMIT之后的語句不允許的變量不允許進行算數運算,會報錯。

正確的寫法一:

<select parameterType='MyApplicationRequest' resultMap='myApplicationMap'> SELECT a.*, FROM tb_user a WHERE 1=1 <if test='ids != null and ids.size()!=0'> AND a.id IN <foreach collection='ids' item='id' index='index' open='(' close=')' separator=','> #{id} </foreach> </if> <if test='statusList != null and statusList.size()!=0'> AND a.status IN <foreach collection='statusList' item='status' index='index' open='(' close=')' separator=','> #{status} </foreach> </if> ORDER BY a.create_time desc LIMIT ${(pageNo-1)*pageSize},${pageSize}; (正確)</select> 正確的寫法二:(推薦)

<select parameterType='MyApplicationRequest' resultMap='myApplicationMap'> SELECT a.*, FROM tb_user a WHERE 1=1 <if test='ids != null and ids.size()!=0'> AND a.id IN <foreach collection='ids' item='id' index='index' open='(' close=')' separator=','> #{id} </foreach> </if> <if test='statusList != null and statusList.size()!=0'> AND a.status IN <foreach collection='statusList' item='status' index='index' open='(' close=')' separator=','> #{status} </foreach> </if> ORDER BY a.create_time desc LIMIT #{offSet},#{limit}; (推薦,代碼層可控)</select>

分析:方法二的寫法,需要再請求參數中額外設置兩個get函數,如下:

@Datapublic class QueryParameterVO { private List<String> ids; private List<Integer> statusList; // 前端傳入的頁碼 private int pageNo; // 從1開始 // 每頁的條數 private int pageSize; // 數據庫的偏移 private int offSet; // 數據庫的大小限制 private int limit; // 這里重寫offSet和limit的get方法 public int getOffSet() { return (pageNo-1)*pageSize; } public int getLimit() { return pageSize; }}

到此這篇關于MyBatis limit分頁設置的實現的文章就介紹到這了,更多相關MyBatis limit分頁內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Mybatis 數據庫
相關文章:
主站蜘蛛池模板: 国产探花系列 | 成人久久久精品国产乱码一区二区 | 国产精选第一页 | 国产精品9| 你懂的国产 | 亚洲视频黄 | 国产成人午夜 | 国产又猛又黄又爽 | 五月天堂网 | 成人精品一二三区 | 午夜久久久久 | 美女久久久久久 | 日韩一区二区视频在线 | av免费在线观看网站 | 黄页在线免费观看 | 超碰天堂| 国产精品美女久久久久av爽 | 九九久久免费视频 | 日本丰满少妇做爰爽爽 | 综合五月| 国产xxxxxx| 香蕉视频链接 | 激情毛片视频 | 天堂资源最新在线 | 国产午夜精品一区二区三区嫩草 | 亚洲七区 | 亚洲天堂aaa | 亚洲精品日韩在线观看 | 新呦u视频一区二区 | 在线高清av | 免费在线观看亚洲 | 国产精品第十页 | 亚洲久视频 | 超碰在线最新 | 免费成人在线网站 | 免费看欧美大片 | 亚洲国产免费视频 | 校园春色 亚洲 | 日韩毛片一级 | 免费视频99 | 蜜臀av粉嫩av懂色av |