Spring MVC gets paging information through pageable objects and Pageabledefault annotations (MongoDB operates pagination via pageable)

Source: Internet
Author: User

Description: Pageable can also be used to manipulate the paging of MongoDB.

An interface defined in the Pageablespring data library that is an abstraction of all paging-related information, through which we can get all the information related to paging (such as pagenumber, pagesize, etc.).

Pageable defines a number of methods, but its core information is only two: the first is the paging information (page, size), and the second is the sorted information.

In spring MVC's request, you simply define a pageable type parameter directly in the parameter of the method, and when spring finds this parameter, Spring automatically assembles the Pageable object according to the request's parameters. The request parameters supported by spring are as follows:

Page , page, starting from 0, default to page No. 0  size, size of each page, default to  sort, sorting related information to Property,property (ASC| DESC) is organized in a way such as Sort=firstname&sort=lastname,desc, which is arranged in reverse order on the basis of the FirstName ordinal arrangement, according to LastName.  

In this way, we can use the parameters of the URL for a variety of personalized query.

Spring data provides the default configuration for @pageabledefault to help us personalize the settings pageable. For example @PageableDefault (value = all, sort = {"id"}, Direction = Sort.Direction.DESC) means that by default we are listed in reverse order of ID, with a size of 15 per page.

@ResponseBody   " List ", method=requestmethod.get)  public"ID" }, Direction = Sort.Direction.DESC) pageable pageable) {      return  Blogrepository.findall (pageable);  }  

Reference:

http://blog.csdn.net/qq_30553235/article/details/76070541 (MongoDB)

http://blog.csdn.net/zsg88/article/details/66025560 (the above content is transferred from this article)

Spring MVC gets paging information through pageable objects and Pageabledefault annotations (MongoDB operates pagination via pageable)

Related Article

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.