layui的两种分页:laypage的div分页和table表格分页

本文介绍了在SpringBoot+Mybatis项目中如何使用layui进行分页展示,包括table表格分页和laypage的div分页方式。在pom.xml中引入依赖后,分别展示了controller层、XML配置以及对应的HTML页面代码。对于table表格分页,通过thymeleaf处理路径,并使用SQL查询限制返回的数据量。而对于laypage的div分页,通过调用queryAll方法设置起始页和每页数量。
摘要由CSDN通过智能技术生成

我用的是springboot+mybatis

1、pom.xml中引入依赖

<!-- mybatis分页插件 -->
		<dependency>
			<groupId>com.github.pagehelper</groupId>
			<artifactId>pagehelper</artifactId>
			<version>5.1.8</version>
		</dependency>

2、controller层

/**
	 *  条件查询/分页
	 * @param pageNum
	 * @param pageSize
	 * @param newsTitle
	 * @param newsAuthor
	 * @return
	 */
	@RequestMapping("/queryAll")
	public String query(Integer pageNum, Integer pageSize, String newsTitle, String newsAuthor) {
		pageNum = (pageNum - 1) * pageSize;
		PageHelper.startPage(pageNum, pageSize);
		List<NewsInfo> newsInfo = newsInfoService.query(pageNum, pageSize, newsTitle, newsAuthor);
		PageInfo<NewsInfo> newsPage = new PageInfo<NewsInfo>(newsInfo);
		Integer count = newsInfoService.count();
		JSONObject json = new JSONObject();
		json.put("data", newsPage.getList());
		json.put("count", count);
		json.put("status", 200);
		return json.toString();
	}

3、xml

<!-- 查询新闻信息 -->
  <select id="query" resultMap="NewsInfo">
  	select * from t_news_info
  		<where>
			<if test="newsTitle != null and newsTitle != ''">
			<bind name="newsTitle" value="'%' + newsTitle + '%'"/>
				and news_title like #{newsTitle}
			</if>
			<if test="newsAuthor != null and newsAuthor != ''">
			<bind name="newsAuthor" value="'%' + newsAuthor + '%'"/>
				and news_author like #{newsAuthor}
			</if>
		</where>
		order by news_modtime desc limit #{pageNum},#{pageSize}
  </select>
  <!-- 查询新闻总数 -->
  <select id="count" resultType="int" >
  	SELECT COUNT(*) from t_news_info
  </select>

order by news_modtime desc limit #{pageNum},#{pageSize} 这里我是根据新闻的修改时间排序

HTML页面(table表格分页)

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<link rel="shortcut icon" th:href="@{/back_images/favicon.ico}" type="image/x-icon" />
<link rel="stylesheet" th:href="@{/layui/css/layui.css}" />
<link rel="stylesheet" th:href="@{/css/bootstrap.css}" />
<link rel="stylesheet" th:href="@{/back_css/back_index.css}" />
<link rel="stylesheet" th:href="@{/back_css/back_admin_list.css}" />
<script type="text/javascript" th:src&
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值