layui的两种分页:laypage的div分页和table表格分页
我用的是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&