Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement MyBatis limit paging settings

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to achieve MyBatis limit paging settings, the article introduces in great detail, has a certain reference value, interested friends must read it!

Incorrect writing: SELECT a WHERE 1 AND a.id IN # {id} AND a.status IN # {status} ORDER BY a.create_time desc LIMIT (# {pageNo}-1) * # {pageSize}, # {pageSize}; / / error

In MyBatis, variables that are not allowed by statements after LIMIT are not allowed to do arithmetic, and an error will be reported.

The correct way to write it is: SELECT a WHERE 1 AND a.id IN # {id} AND a.status IN # {status} ORDER BY a.create_time desc LIMIT ${(pageNo-1) * pageSize}, ${pageSize} (correct) correct writing two: (recommended) SELECT a WHERE 1 AND a.id IN # {id} AND a.status IN # {status} ORDER BY a.create_time desc LIMIT # {offSet}, # {limit}; (recommended, the code layer is controllable)

Analysis: to write method 2, you need to set two additional get functions in the request parameters, as follows:

@ Datapublic class QueryParameterVO {private List ids; private List statusList; / / Page number passed in from the front end private int pageNo; / / number of entries per page from 1 / / offset of the database private int offSet; / / size limit of the database private int limit; / / here rewrite the get method public int getOffSet () {return (pageNo-1) * pageSize;} public int getLimit () {return pageSize of offSet and limit }} the above is all the contents of the article "how to achieve MyBatis limit paging settings". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report