百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
T

thymeleaf-spring-data-dialect

> 编程语言
开源

使用 thymeleaf 和 Spring Data 简化数据分页

199 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

使用 thymeleaf 和 Spring Data 简化数据分页

Thymeleaf Spring Data Dialect

Data pagination made easy with thymeleaf and spring data.

This is a dialect for Thymeleaf that provides some attributes to create pagination and sorting elements, bootstrap style, based on Spring Data.

Usage

Maven dependency:

xml

	io.github.jpenren
	thymeleaf-spring-data-dialect
	3.6.0

Add the Spring Data dialect to your existing Thymeleaf template engine:

java
templateEngine.addDialect(new SpringDataDialect());		// This line adds the dialect to Thymeleaf

If using Spring Boot you can add the following line and the ThymeleafAutoConfiguration class will add the dialect to the template engine.

java
    @Bean
    public SpringDataDialect springDataDialect() {
        return new SpringDataDialect();
    }

This will introduce the sd namespace, and the new attribute processors that you to use in your pages: pagination, pagination-sort, pagination-summary, pagination-url, page-object, pagination-qualifier and page-size-selector.

Examples

In your @Controller

java
@RequestMapping("/users")
public String list(ModelMap model, @SortDefault("username") Pageable pageable){
	model.addAttribute("page", userService.find(pageable));
	
	return "users/list";
}

Your html page looks like:

xml

	
		

		  Username
		  First name
		  Last Name
		  
		

	
	
		

		  Username
		  Name
		  Last Name
		  edit
		

	

    
    

Use optional attribute sd:pagination-split to configure the number of links to show.

Pagination with pager:

xml

    

        
        
&laquo;

        
1 (current)

    

Aligned links:

xml

    

        
        
&laquo;

        
1 (current)

    

Compact pager:

xml

Page size selector (default requires your own javascript code, no action associated):

xml
Show  entries

Page size selector (with javascript code implemented):

xml
Show  entries

Page size selector (dropdown):

xml

Multiple tables on the same page:

On your @Controller

java
@RequestMapping("/users")
public String list(ModelMap model, @Qualifier("foo") Pageable first, @Qualifier("bar") Pageable second){
	model.addAttribute("page", userService.find(first));
	model.addAttribute("barPage", userService.find(second));
	
	return "users/list";
}
xml

        
	
	

        
	

By default SpringDataDialect search in the request for the attribute "page" or if one attribute of type org.springframework.data.domain.Page exists. To use another model attribute, use sd:page-object="${attrName}"

To specify the pagination url use sd:pagination-url tag:

xml

    

        
        
&laquo;

        
1 (current)

    

Sort Icons

The generated HTML has the CSS classes sorted, sorted-asc and sorted-desc. This allows you to quite easily add some custom CSS to have sort icons in the table headers.

Example with FontAwesome:

table.table thead .sorted:after{
	display: inline-block;
	font-family: 'FontAwesome';
	opacity: 0.8;
	margin-left: 1em;
}
table.table thead .sorted.sorted-desc:after{
	content: "\f15e";
}
table.table thead .sorted.sorted-asc:after{
	content: "\f15d";
}

Example with Unicode characters:

.sorted-desc::after, .sorted-asc::after {
    float: right;
}

.sorted-desc::after{
    content:"\25BC";
}

.sorted-asc::after{
    content: "\25B2";
}

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Java

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言