I try to make pagination in my web site.
my PostController.java file contains:
@GetMapping("/")
public String index(Model model) {
return findPaginated(0, model);
}
@GetMapping("/page/{pageNo}")
public String findPaginated(
@PathVariable("pageNo") int pageNo,
Model model
) {
int pageSize = 3;
Page<Post> page = postService.findPaginated(pageNo, pageSize);
List<Post> listPosts = page.getContent();
model.addAttribute("currentPage", pageNo);
model.addAttribute("totalPages", page.getTotalPages());
model.addAttribute("totalItems", page.getTotalElements());
model.addAttribute("page", page);
int totalPages = page.getTotalPages();
if (totalPages > 0) {
List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages).boxed().collect(Collectors.toList());
model.addAttribute("pageNumbers", pageNumbers);
}
model.addAttribute("listPosts", listPosts);
return "index";
}
and index.html file contains:
<head xmlna:th="http://www.thymeleaf.org">
--snip--
<link href="assets/css/font-awesome.min.css" rel="stylesheet">
--snip--
</head>
<body>
--snip--
<!-- ADDING PAGINATION-->
<nav aria-label="...">
<ul class="pagination">
<li class="page-item">
<a class="page-link"
th:href="@{'/page/' + ${currentPage - 1}}"
th:if="${currentPage < totalPages + 1 and currentPage > 1}">Previous</a>
</li>
<li th:class="${pageNumber == page.getNumber() + 1} ? 'page-item active': 'page-item'"
th:each="pageNumber: ${pageNumbers}" th:if="${page.getTotalPages() > 0}">
<a class="page-link"
th:href="@{'/page/' + ${pageNumber}}"
th:text="${pageNumber}">
</a>
</li>
<li class="page-item">
<a class="page-link"
th:href="@{'/page/' + ${currentPage + 1}}"
th:if="${currentPage < totalPages and currentPage >= 1}">Next</a>
</li>
</ul>
</nav>
<!-- /ADDING PAGINATION-->
--snip--
</body>
When program runs for the first time everything looks right. So I add some posts (this app is about writing posts and showing them in index.html file) and when I want to go for example:
localhost:8080/page/1
css, js and img files didn't upload. I inspected and checked network, and it shows me localhost:8080/page/assets/css/font-awesome.min.css
didn't upload.Actually, it must be localhost:8080/assets/css/font-awesome.min.css
. But why exactly this path it shows me?
How could I fix it?
If you didn't get question, then I uploaded some extra images for better understanding:
Thanks in advance. I hope you get it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…