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