|
|
|
|
1
|
-# Pagination
|
|
|
|
|
1
|
+# Part 6 - Pagination
|
2
|
* To optimize performance, it is important to limit the amount of data returned, especially in the case of a mobile client.
|
2
|
* To optimize performance, it is important to limit the amount of data returned, especially in the case of a mobile client.
|
3
|
* REST services have the ability to give clients access large datasets in manageable chunks, by splitting the data into discrete pages or _paging data_.
|
3
|
* REST services have the ability to give clients access large datasets in manageable chunks, by splitting the data into discrete pages or _paging data_.
|
4
|
* For this lab, we will approach this by implementing the _page number pagination pattern_.
|
4
|
* For this lab, we will approach this by implementing the _page number pagination pattern_.
|
|
|
|
|
41
|
|
41
|
|
42
|
|
42
|
|
43
|
-
|
43
|
-
|
44
|
-# Taking Action!
|
|
|
|
|
44
|
+# Part 6.1 - Load Dummy Poll Data
|
45
|
|
45
|
|
46
|
-1. Create a `src/main/resource/import.sql` file with [DML statements](http://lmgtfy.com/?q=DML+statement) for populating the database upon bootstrap. The `import.sql` should insert at least 10 polls, each with 3 or more options.
|
|
|
|
|
46
|
+* Create a `src/main/resource/import.sql` file with [DML statements](http://lmgtfy.com/?q=DML+statement) for populating the database upon bootstrap. The `import.sql` should insert at least 15 polls, each with 3 or more options.
|
47
|
* Below is an example of `SQL` statements for creating a single poll with only one option.
|
47
|
* Below is an example of `SQL` statements for creating a single poll with only one option.
|
48
|
|
48
|
|
49
|
* Poll Creation
|
49
|
* Poll Creation
|
|
|
|
|
57
|
insert into option (option_id, option_value, poll_id) values (1, 'Red', 1);
|
57
|
insert into option (option_id, option_value, poll_id) values (1, 'Red', 1);
|
58
|
```
|
58
|
```
|
59
|
|
59
|
|
60
|
-2. Restart your application.
|
|
|
61
|
-3. Ensure database is populated by `import.sql`.
|
|
|
62
|
-4. Utilize Spring's built-in page number pagination support by researching the `PagingAndSortingRepository` class.
|
|
|
63
|
-5. Ensure the `Controller` methods handle `Pageable` arguments.
|
|
|
64
|
-6. Send a `GET` request to `http://localhost:8080/polls?page=0&size=2` via Postman.
|
|
|
|
|
60
|
+* Restart your application.
|
|
|
61
|
+* Use Postman to ensure database is populated by `import.sql`.
|
|
|
62
|
+
|
|
|
63
|
+
|
|
|
64
|
+# Part 6.2 - Spring's Built-in Pagination
|
|
|
65
|
+* Make use of Spring's built-in page number pagination support by researching `org.springframework.data.repository.PagingAndSortingRepository`.
|
|
|
66
|
+* Modify respective `Controller` methods to handle `Pageable` arguments.
|
|
|
67
|
+* Send a `GET` request to `http://localhost:8080/polls?page=0&size=2` via Postman.
|
65
|
* Ensure the response is a `JSON` object with pagination-specific information.
|
68
|
* Ensure the response is a `JSON` object with pagination-specific information.
|