LIMIT usage in MYSQL

sql in mapper file:

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

  (property defined in entity class)

  start: The number of records to start from.

  size: Read 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>

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

The front end will page: which page

   rows(size): how many lines per page

   These two parameters are passed to the background.

    Through these two parameters, the start calculation method can be calculated start=size(page-1)

   Then put size and start into 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.

   Then pass map as a parameter to the interface of dao.

 

 

Note:

limit is the syntax of mysql
select * from table limit m,n
where m refers to the index of the beginning of the record, starting from 0, indicating that the first record
n ​​refers to the m+1th starting, take n.
select * from tablename limit 2,4
is to take out the 3rd to 6th, 4 records

 

Reprinted from: https://zhidao.baidu.com/question/266421833.html AND http://www.cnblogs.com/yululiang/p/6497534.html It is convenient to find it later

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325565260&siteId=291194637