mvc fix pagination
This commit is contained in:
parent
444728c8fc
commit
dffe1aeae2
@ -32,6 +32,7 @@ public class UserBookController {
|
|||||||
private static final String AUTHORS_ATTRIBUTE = "authors";
|
private static final String AUTHORS_ATTRIBUTE = "authors";
|
||||||
private static final String TYPE_ATTRIBUTE = "typeId";
|
private static final String TYPE_ATTRIBUTE = "typeId";
|
||||||
private static final String TYPES_ATTRIBUTE = "types";
|
private static final String TYPES_ATTRIBUTE = "types";
|
||||||
|
private static final String PARAMS_ATTRIBUTE = "searchParams";
|
||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final BookService bookService;
|
private final BookService bookService;
|
||||||
@ -70,7 +71,7 @@ public class UserBookController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public String getFavorites(
|
public String favorites(
|
||||||
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
|
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
|
||||||
Model model,
|
Model model,
|
||||||
@AuthenticationPrincipal UserPrincipal principal) {
|
@AuthenticationPrincipal UserPrincipal principal) {
|
||||||
@ -94,7 +95,7 @@ public class UserBookController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(Constants.API_URL + "/search")
|
@GetMapping(Constants.API_URL + "/search")
|
||||||
public String getAll(
|
public String search(
|
||||||
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
|
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
|
||||||
@RequestParam(name = TYPE_ATTRIBUTE, defaultValue = "-1") Long typeId,
|
@RequestParam(name = TYPE_ATTRIBUTE, defaultValue = "-1") Long typeId,
|
||||||
@RequestParam(name = AUTHOR_ATTRIBUTE, defaultValue = "-1") Long authorId,
|
@RequestParam(name = AUTHOR_ATTRIBUTE, defaultValue = "-1") Long authorId,
|
||||||
@ -107,6 +108,7 @@ public class UserBookController {
|
|||||||
model.addAttribute(AUTHOR_ATTRIBUTE, authorId);
|
model.addAttribute(AUTHOR_ATTRIBUTE, authorId);
|
||||||
model.addAttribute(TYPES_ATTRIBUTE, typeService.getAll());
|
model.addAttribute(TYPES_ATTRIBUTE, typeService.getAll());
|
||||||
model.addAttribute(AUTHORS_ATTRIBUTE, authorService.getAll());
|
model.addAttribute(AUTHORS_ATTRIBUTE, authorService.getAll());
|
||||||
|
model.addAttribute(PARAMS_ATTRIBUTE, "typeId="+typeId+"&authorId="+authorId);
|
||||||
model.addAttribute(PAGE_ATTRIBUTE, page);
|
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||||
return BOOK_SEARCH_VIEW;
|
return BOOK_SEARCH_VIEW;
|
||||||
}
|
}
|
||||||
|
@ -65,10 +65,8 @@
|
|||||||
url=${'api/1.0/search'},
|
url=${'api/1.0/search'},
|
||||||
totalPages=${totalPages},
|
totalPages=${totalPages},
|
||||||
currentPage=${currentPage},
|
currentPage=${currentPage},
|
||||||
param1name=${'typeId'},
|
searchParams=${searchParams}
|
||||||
param1value=${typeId},
|
)}" />
|
||||||
param2name=${'authorId'},
|
|
||||||
param2value=${authorId}) }" />
|
|
||||||
</th:block>
|
</th:block>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
</nav>
|
</nav>
|
||||||
</th:block>
|
</th:block>
|
||||||
|
|
||||||
<th:block th:fragment="pagination-with-params (url, totalPages, currentPage, param1name, param1value, param2name, param2value)">
|
<th:block th:fragment="pagination-with-params (url, totalPages, currentPage, searchParams)">
|
||||||
<nav th:if="${totalPages > 1}" th:with="
|
<nav th:if="${totalPages > 1}" th:with="
|
||||||
maxPage=2,
|
maxPage=2,
|
||||||
currentPage=${currentPage + 1}">
|
currentPage=${currentPage + 1}">
|
||||||
@ -59,10 +59,7 @@
|
|||||||
<th:block th:if="${currentPage > maxPage + 1}">
|
<th:block th:if="${currentPage > maxPage + 1}">
|
||||||
<li class="page-item">
|
<li class="page-item">
|
||||||
<a class="page-link" aria-label="Previous"
|
<a class="page-link" aria-label="Previous"
|
||||||
th:href="@{/{url}?page=0&{param1name}={param1value}&{param2name}={param2value}
|
th:href="@{/{url}?page=0&(url=${url})} + ${searchParams}">
|
||||||
(url=${url},
|
|
||||||
param1name=${param1name},param1value=${param1value},
|
|
||||||
param2name=${param2name},param2value=${param2value})}">
|
|
||||||
<span aria-hidden="true">«</span>
|
<span aria-hidden="true">«</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
@ -75,10 +72,7 @@
|
|||||||
<li class="page-item" th:each="page : ${#numbers.sequence(seqFrom, seqTo)}"
|
<li class="page-item" th:each="page : ${#numbers.sequence(seqFrom, seqTo)}"
|
||||||
th:classappend="${page == currentPage} ? 'active' : ''">
|
th:classappend="${page == currentPage} ? 'active' : ''">
|
||||||
<a class=" page-link"
|
<a class=" page-link"
|
||||||
th:href="@{/{url}?page={page}&{param1name}={param1value}&{param2name}={param2value}
|
th:href="@{/{url}?page={page}&(url=${url},page=${page - 1})} + ${searchParams}">
|
||||||
(url=${url},page=${page - 1},
|
|
||||||
param1name=${param1name},param1value=${param1value},
|
|
||||||
param2name=${param2name},param2value=${param2value})}">
|
|
||||||
<span th:text="${page}" />
|
<span th:text="${page}" />
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
@ -90,10 +84,7 @@
|
|||||||
</li>
|
</li>
|
||||||
<li class="page-item">
|
<li class="page-item">
|
||||||
<a class="page-link" aria-label="Next"
|
<a class="page-link" aria-label="Next"
|
||||||
th:href="@{/{url}?page={page}&{param1name}={param1value}&{param2name}={param2value}
|
th:href="@{/{url}?page={page}&(url=${url},page=${totalPages - 1})} + ${searchParams}">
|
||||||
(url=${url},page=${totalPages - 1},
|
|
||||||
param1name=${param1name},param1value=${param1value},
|
|
||||||
param2name=${param2name},param2value=${param2value})}">
|
|
||||||
<span aria-hidden="true">»</span>
|
<span aria-hidden="true">»</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user