#171 - Switched to Thymeleaf Spring Data dialect for pagination in views.
Added dependency and bean definition for the SpringDataDialect. Templates now use three different elements of the Thymeleaf Spring Data support: - Pagination information (pagination summary) - The pagination links including first / previous and next / last links - Pagination links to navigate through the pages
This commit is contained in:
@@ -43,6 +43,12 @@
|
|||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.jpenren</groupId>
|
||||||
|
<artifactId>thymeleaf-spring-data-dialect</artifactId>
|
||||||
|
<version>2.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.webjars</groupId>
|
<groupId>org.webjars</groupId>
|
||||||
<artifactId>jquery</artifactId>
|
<artifactId>jquery</artifactId>
|
||||||
|
|||||||
@@ -20,8 +20,10 @@ import javax.annotation.PostConstruct;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||||
|
import org.thymeleaf.dialect.springdata.SpringDataDialect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
@@ -44,6 +46,11 @@ public class Application extends WebMvcConfigurerAdapter {
|
|||||||
resourceChain(true);
|
resourceChain(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
SpringDataDialect springDataDialect() {
|
||||||
|
return new SpringDataDialect();
|
||||||
|
}
|
||||||
|
|
||||||
@Autowired UserRepository repo;
|
@Autowired UserRepository repo;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sd="http://www.thymeleaf.org/spring-data">
|
||||||
<head>
|
<head>
|
||||||
<title>User Center</title>
|
<title>User Center</title>
|
||||||
|
|
||||||
@@ -50,18 +50,11 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav class="text-center">
|
<nav class="text-center">
|
||||||
<ul class="pagination" th:with="total = ${users.totalPages}">
|
<div sd:pagination-summary="true">Pagination information</div>
|
||||||
<li th:if="${users.hasPrevious()}">
|
<ul class="pagination" sd:pagination="full">
|
||||||
<a th:href="@{${baseUri}(page=${users.previousPageable().pageNumber})}" aria-label="Previous">
|
<!-- Pagination created by the Thymeleaf Spring Data dialect, this content is just for mockup -->
|
||||||
<span aria-hidden="true">«</span>
|
<li class="disabled"><a href="#" aria-label="Previous"><span aria-hidden="true">«</span></a></li>
|
||||||
</a>
|
<li class="active"><a href="#">1 <span class="sr-only">(current)</span></a></li>
|
||||||
</li>
|
|
||||||
<li th:each="page : ${#numbers.sequence(0, total - 1)}"><a th:href="@{${baseUri}(page=${page})}" th:text="${page + 1}">1</a></li>
|
|
||||||
<li th:if="${users.hasNext()}">
|
|
||||||
<a th:href="@{${baseUri}(page=${users.nextPageable().pageNumber})}" aria-label="Next">
|
|
||||||
<span aria-hidden="true">»</span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
@@ -70,7 +63,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th>Firstname</th>
|
<th><a sd:pagination-sort="firstname">Firstname</a></th>
|
||||||
<th>Lastname</th>
|
<th>Lastname</th>
|
||||||
<th>Nationality</th>
|
<th>Nationality</th>
|
||||||
<th>City</th>
|
<th>City</th>
|
||||||
@@ -94,6 +87,8 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<ul class="pagination" sd:pagination="aligned-links"></ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user