Skip to content

Commit 75d25de

Browse files
committed
spring-projects#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
1 parent 91c06fe commit 75d25de

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

web/querydsl/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
<scope>runtime</scope>
4444
</dependency>
4545

46+
<dependency>
47+
<groupId>io.github.jpenren</groupId>
48+
<artifactId>thymeleaf-spring-data-dialect</artifactId>
49+
<version>2.1.0</version>
50+
</dependency>
51+
4652
<dependency>
4753
<groupId>org.webjars</groupId>
4854
<artifactId>jquery</artifactId>

web/querydsl/src/main/java/example/users/Application.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
import org.springframework.beans.factory.annotation.Autowired;
2121
import org.springframework.boot.SpringApplication;
2222
import org.springframework.boot.autoconfigure.SpringBootApplication;
23+
import org.springframework.context.annotation.Bean;
2324
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
2425
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
26+
import org.thymeleaf.dialect.springdata.SpringDataDialect;
2527

2628
/**
2729
* @author Christoph Strobl
@@ -44,6 +46,11 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
4446
resourceChain(true);
4547
}
4648

49+
@Bean
50+
SpringDataDialect springDataDialect() {
51+
return new SpringDataDialect();
52+
}
53+
4754
@Autowired UserRepository repo;
4855

4956
@PostConstruct

web/querydsl/src/main/resources/templates/index.html

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
<!DOCTYPE html>
2-
<html lang="en" xmlns:th="http://www.thymeleaf.org">
2+
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sd="http://www.thymeleaf.org/spring-data">
33
<head>
44
<title>User Center</title>
5-
5+
66
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
77
<meta name="viewport" content="width=device-width, initial-scale=1" />
8-
8+
99
<link rel="stylesheet" th:href="@{/webjars/bootstrap/css/bootstrap.min.css}" />
1010
</head>
1111

1212
<body>
1313
<div class="container-fluid">
1414
<h1>User Center</h1>
15-
15+
1616
<div class="panel panel-default">
1717
<div class="panel-heading">
1818
<h3 class="panel-title">Search</h3>
1919
</div>
2020
<div class="panel-body">
21-
21+
2222
<form action="/">
23-
23+
2424
<div class="form-group col-sm-6">
2525
<label for="firstname" class="control-label">Firstname:</label>
2626
<input id="firstname" name="firstname" th:value="${#httpServletRequest.getParameter('firstname')}" type="text" class="form-control" autofocus="autofocus" />
@@ -44,33 +44,26 @@ <h3 class="panel-title">Search</h3>
4444
<div class="form-group col-sm-12">
4545
<button id="submit" type="submit" class="btn btn-default">Submit</button>
4646
</div>
47-
47+
4848
</form>
4949
</div>
5050
</div>
51-
51+
5252
<nav class="text-center">
53-
<ul class="pagination" th:with="total = ${users.totalPages}">
54-
<li th:if="${users.hasPrevious()}">
55-
<a th:href="@{${baseUri}(page=${users.previousPageable().pageNumber})}" aria-label="Previous">
56-
<span aria-hidden="true">&laquo;</span>
57-
</a>
58-
</li>
59-
<li th:each="page : ${#numbers.sequence(0, total - 1)}"><a th:href="@{${baseUri}(page=${page})}" th:text="${page + 1}">1</a></li>
60-
<li th:if="${users.hasNext()}">
61-
<a th:href="@{${baseUri}(page=${users.nextPageable().pageNumber})}" aria-label="Next">
62-
<span aria-hidden="true">&raquo;</span>
63-
</a>
64-
</li>
53+
<div sd:pagination-summary="true">Pagination information</div>
54+
<ul class="pagination" sd:pagination="full">
55+
<!-- Pagination created by the Thymeleaf Spring Data dialect, this content is just for mockup -->
56+
<li class="disabled"><a href="#" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
57+
<li class="active"><a href="#">1 <span class="sr-only">(current)</span></a></li>
6558
</ul>
6659
</nav>
67-
60+
6861
<table class="table table-striped">
6962
<thead>
7063
<tr>
7164
<th>#</th>
7265
<th></th>
73-
<th>Firstname</th>
66+
<th><a sd:pagination-sort="firstname">Firstname</a></th>
7467
<th>Lastname</th>
7568
<th>Nationality</th>
7669
<th>City</th>
@@ -93,8 +86,10 @@ <h3 class="panel-title">Search</h3>
9386
</tr>
9487
</tbody>
9588
</table>
96-
89+
90+
<ul class="pagination" sd:pagination="aligned-links"></ul>
91+
9792
</div>
98-
93+
9994
</body>
10095
</html>

0 commit comments

Comments
 (0)