SpringBoot Mybatis-plus thymeleaf简单分页查询

效果
在这里插入图片描述

mybatis-plus分页插件 config

@Configuration
@EnableTransactionManagement
public class MybatisPlusConfig {
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //分页
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
    @Bean
    public ConfigurationCustomizer configurationCustomizer() {
        return configuration -> configuration.setUseDeprecatedExecutor(false);
    }
}

实体类

@AllArgsConstructor
@Data
@EqualsAndHashCode(callSuper = false)
public class Category implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 分类编号
     */
    @TableId(value = "cat_id", type = IdType.AUTO)
    private Integer catId;

    private String catName;
    
}

Service层

@Override
    public Page<Category> getCategoryPage(Integer cur, Integer size) {
        Page<Category> categoryPage = new Page<>(cur, size);
        return categoryMapper.selectPage(categoryPage, null);
    }

Controller层

@Override
    public Page<Category> getCategoryPage(Integer cur, Integer size) {
        Page<Category> categoryPage = new Page<>(cur, size);
        return categoryMapper.selectPage(categoryPage, null);
    }
<tbody>
					<tr th:each="category:${categoryPage.records}">
						<td th:text="${category.catId}"></td>
						<td th:text="${category.catName}"></td>

						<td>
							<a th:href="@{/updateCategory/{id}(id=${category.catId})}">
								<button type="button" class="btn btn-primary">修改</button>
							</a>&nbsp;
							<a th:href="@{/category/deleteCategoryById/{id}(id=${category.catId})}">
								<button type="button" class="btn btn-danger">删除</button>
							</a>
						</td>
					</tr>
					</tbody>

				</table>
				<nav aria-label="Page navigation example">
					<ul class="pagination">
						<th:block th:if="${categoryPage.hasPrevious()}">
							<li class="page-item">
								<a class="page-link" th:href="@{/categoryPage/{cur}(cur=${categoryPage.current}-1)}"
								   aria-label="Previous">
									<span aria-hidden="true">&laquo;</span>
								</a>
							</li>
						</th:block>
						<th:block th:if="${!categoryPage.hasPrevious()}">
							<li class="page-item">
								<a class="page-link" th:href="@{/categoryPage/{cur}(cur=${categoryPage.current})}"
								   aria-label="Previous">
									<span aria-hidden="true">&laquo;</span>
								</a>
							</li>
						</th:block>
						<th:block th:if="${categoryPage.getCurrent()<=3}"
						          th:each="i:${#numbers.sequence(1,categoryPage.pages)}">

							<li class="page-item"><a class="page-link" th:href="@{/categoryPage/{cur}(cur=${i})}"
							                         th:text="${i}">1</a></li>


						</th:block>
						<th:block th:if="${categoryPage.hasNext()}">
							<li class="page-item">
								<a class="page-link" th:href="@{/categoryPage/{cur}(cur=${categoryPage.current}+1)}"
								   aria-label="Next">
									<span aria-hidden="true">&raquo;</span>
								</a>
							</li>
						</th:block>
						<th:block th:if="${!categoryPage.hasNext()}">
							<li class="page-item">
								<a class="page-link" th:href="@{/categoryPage/{cur}(cur=${categoryPage.current})}"
								   aria-label="Next">
									<span aria-hidden="true">&raquo;</span>
								</a>
							</li>
						</th:block>
					</ul>
				</nav>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值