原文地址:http://www.work100.net/training/monolithic-project-iot-cloud-admin-manager-page-search.html
更多教程:光束云 - 免费课程
分页功能
序号 | 文内章节 | 视频 |
---|---|---|
1 | 概述 | - |
2 | 修改AuthManagerMapper.xml | - |
3 | 修改AuthManagerDao接口 | - |
4 | 定义AbstractBaseDomain | - |
5 | 定义PageInfo | - |
6 | 修改AuthManagerService接口 | - |
7 | 修改AuthManagerServiceImpl实现 | - |
8 | 修改ManagerController | - |
9 | 视图页面修改 | - |
10 | 测试验证 | - |
11 | 实例源码 | - |
请参照如上章节导航
进行阅读
1.概述
接下来实现 账户列表
页面的 分页功能
,预期实现的画面效果如下:

实现要点:
- 视图页面使用
jquery.dataTables
,并使用 JS 进行封装 - 通过 Ajax 进行 POST 请求
- 定义 PageInfo 对象用于视图与控制器间的数据传输
2.修改AuthManagerMapper.xml
增加 2 个语句定义:
分页查询 pageSearch
<select id="pageSearch" resultType="AuthManager" parameterType="java.util.Map">
SELECT
<include refid="authManagerColumns" />
FROM
auth_manager AS a
<where>
<if test="userName != null and userName != ''">
AND a.user_name LIKE CONCAT('%', #{userName}, '%')
</if>
<if test="roles != null and roles != ''">
AND a.roles LIKE CONCAT('%', #{roles}, '%')
</if>
<if test="status != -1">
AND a.status = #{status}
</if>
</where>
ORDER BY a.id DESC
LIMIT #{start}, #{length}
</select>
统计查询结果记录数 count
<select id="count" resultType="int">
SELECT
COUNT(*)
FROM
auth_manager AS a
<where>
<if test="userName != null and userName != ''">
AND a.user_name LIKE CONCAT('%', #{userName}, '%')
</if>
<if test="roles != null and roles != ''">
AND a.roles LIKE CONCAT('%', #{roles}, '%')
</if>
<if test="status != -1">
AND a.status = #{status}
</if>
</where>
</select>
3.修改AuthManagerDao接口
增加 2 个方法:
分页查询 pageSearch
/**
* 分页查询
*
* @param params 查询条件及分页参数
* @return
*/
List<AuthManager> pageSearch(Map<String, Object> params);
统计查询结果记录数 count
/**
* 计数统计
*
* @param authManager 查询条件
* @return
*/
int count(AuthManager authManager);
4.定义AbstractBaseDomain
定义一个通用的抽象实体类,其它数据对象模型均继承它。
新增 AbstractBaseDomain 抽象类
在 iot-cloud-commons
项目下新增 AbstractBaseDomain
类,代码如下:
package net.work100.training.stage2.iot.cloud.commons.dto;
import java.io.Serializable;
import java.util.Date;
/**
* <p>Title: AbstractBaseDomain</p>
* <p>Description: </p>
*
* @author liuxiaojun
* @date 2020-03-14 14:44
* ------------------- History -------------------
* <date> <author> <desc>
* 2020-03-14 liuxiaojun 初始创建
* -----------------------------------------------
*/
public abstract class AbstractBaseDomain implements Serializable {
private Long id;
private Date created;
private Date updated;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getUpdated() {
return updated;
}
public void setUpdated(Date updated) {
this.updated = updated;
}
}
修改 AuthManager 类
首先,修改 iot-cloud-domain
项目的 POM
文件,增加项目依赖:
<dependencies>
<dependency>
<groupId>net.work100.training.stage2</groupId>
<artifactId>iot-cloud-commons</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
然后,修改 AuthManager
类的定义,使其继承 AbstractBaseDomain
,代码如下:
package net.work100.training.stage2.iot.cloud.domain;
import net.work100.training.stage2.iot.cloud.commons.dto.AbstractBaseDomain;
import java.io.Serializable;
import java.util.Date;
/**
* <p>Title: AuthManager</p>
* <p>Description: 管理员账户表</p>
* <p>Url: http://www.work100.net/training/monolithic-project-iot-cloud-admin.html</p>
*
* @author liuxiaojun
* @date 2020-02-23 22:42
* ------------------- History -------------------
* <date> <author> <desc>
* 2020-02-23 liuxiaojun 初始创建
* -----------------------------------------------
*/
public class AuthManager extends AbstractBaseDomain {
private String userKey;
private String userName;
private String password;
/**
* 状态:0=inactive, 1=active, 2=locked, 3=deleted
*/
private int status;
private boolean superuser;
/**
* 角色:admin, editor
*/
private String roles;
private Date modifyPasswordTime;
public String getUserKey() {
return userKey;
}
public void setUserKey(String userKey) {
this.userKey = userKey;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public boolean isSuperuser() {
return superuser;
}
public void setSuperuser(boolean superuser) {
this.superuser = superuser;
}
public String getRoles() {
return roles;
}
public void setRoles(String roles) {
this.roles = roles;
}
public Date getModifyPasswordTime() {
return modifyPasswordTime;
}
public void setModifyPasswordTime