Leon df9ed504fd updated `README.md` преди 7 години
src updated resources преди 7 години
.gitignore Create .gitignore преди 7 години
README.md updated `README.md` преди 7 години
pom.xml first commit преди 7 години

README.md

-

Pagination

  • To optimize performance, it is important to limit the amount of data returned, especially in the case of a mobile client.
  • REST services have the ability to give clients access large datasets in manageable chunks, by splitting the data into discrete pages or paging data.
  • For this lab, we will approach this by implementing the page number pagination pattern.

-

Get Data From Page

  • For example, a client wanting a blog post in page 3 of a hypothetical blog service can use a GET method resembling the following: http://blog.example.com/posts?page=3

-

Limit Data Retrieved From Page

  • It is possible for the client to override the default page size by passing in a page-size parameter: http://blog.example.com/posts?page=3&size=20

-

Pagination Specific Information

  • Pagination-specific information includes
    • total number of records
    • total number of pages
    • current page number
    • page size

-

Pagination Data

  • In the above scenario, one would expect a response body with pagination infromation closely resembling the JSON object below.
{
"data": [
         ... Blog Data
    ],
    "totalPages": 9,
    "currentPageNumber": 2,
    "pageSize": 10,
    "totalRecords": 90
}
  • Read more about REST pagination in Spring by clicking here.

-

Taking Action!

  1. Create a src/main/resource/import.sql file with DML statements for populating the database upon bootstrap. The import.sql should insert at least 10 polls, each with 3 or more options.

    • Below is an example of SQL statements for creating a single poll with only one option.

      • Poll Creation

        insert into poll (poll_id, question) values (1, 'What is your favorite color?');
        
      • Option Creation

        insert into option (option_id, option_value, poll_id) values (1, 'Red', 1);
        
  2. Restart your application.

  3. Ensure database is populated by import.sql.

  4. Utilize Spring's built-in page number pagination support by researching the PagingAndSortingRepository class.

  5. Ensure the Controller methods handle Pageable arguments.

  6. Send a GET request to http://localhost:8080/polls?page=0&size=2 via Postman.

    • Ensure the response is a JSON object with pagination-specific information.