LIMIT usage in MYSQL

Source: Internet
Author: User

SQL in the Mapper file:

--------------------------------------------------------------------------------------------

(attributes defined in the entity class)

Start: Starts with the first few records.

Size: Reads several records.

Select Id= "Findallusers" parametertype= "Map" resulttype= "entity. Iuser ">

SELECT * FROM NewUsers
<where>
User_name like #{user_name,jdbctype=varchar}
</where>
Limit #{start,jdbctype=integer},#{size,jdbctype=integer}
</select>

-------------------------------------------------------------------

Front End Will page: Page No.

Rows (size): How many bars per page

These two parameters are uploaded to the background.

Using these two parameters, we can calculate the start calculation method Start=size (page-1)

Then put the size and start into the map

Simple code example

Map map=new HashMap ();

Map.put ("Start", start);

Map.put ("size", size);

Don't forget to convert start and size to integer.

It then passes the map as a parameter to the DAO's interface.

Note:

Limit is the syntax of MySQL
SELECT * FROM table limit M,n
where m refers to the beginning of the record index, starting from 0, indicating the first record
n means starting from section m+1 and taking N.
SELECT * FROM tablename limit 2,4
Take out 3rd to 6th, 4 records

Turn from: https://zhidao.baidu.com/question/266421833.html and http://www.cnblogs.com/yululiang/p/6497534.html convenient for later search

LIMIT usage in MYSQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.