概述
本开发文档详细描述了MIS系统中的分页查询用户接口的设计与实现。通过该接口,用户可以根据各种条件查询用户信息,返回符合条件的用户列表,并支持分页显示。
功能需求
- 分页查询用户:用户可以通过提交查询条件来分页获取用户信息,包括用户名、姓名、手机号、邮箱等。
- 权限控制:确保只有具有特定权限的用户可以访问此接口。
接口详情
分页查询用户接口
接口路径
/mis_user/searchByPage
请求方法
POST
接口描述
该接口用于分页查询用户信息。用户可以通过提交查询条件来获取符合条件的用户列表,并支持分页显示。
POST 分页查询用户
POST /user/searchByPage
Body 请求参数
{
"id": null,
"nickName": "",
"name": "",
"phone": "",
"email": "",
"status": null,
"order": "",
"page": 1,
"length": 10
}
请求参数
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| Token | header | string | 否 | none |
| body | body | object | 否 | none |
| » id | body | integer | 否 | none |
| » nickName | body | string | 否 | none |
| » name | body | string | 否 | none |
| » phone | body | string | 否 | none |
| body | string | 否 | none | |
| » status | body | integer | 否 | none |
| » order | body | string | 否 | none |
| » page | body | integer | 否 | none |
| » length | body | integer | 否 | none |
返回示例
200 Response
{
"msg": "string",
"result": {
"totalCount": 0,
"pageSize": 0,
"totalPage": 0,
"pageIndex": 0,
"list": [
"string"
]
},
"code": 0
}
返回结果
| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | 成功 | Inline |
返回数据结构
状态码 200
| 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
|---|---|---|---|---|---|
| » msg | string | true | none | none | |
| » result | object | true | none | none | |
| »» totalCount | integer | true | none | none | |
| »» pageSize | integer | true | none | none | |
| »» totalPage | integer | true | none | none | |
| »» pageIndex | integer | true | none | none | |
| »» list | [string] | true | none | none | |
| » code | integer | true | none | none |
实现细节
控制器代码
@PostMapping("/searchByPage")
@SaCheckLogin
@SaCheckPermission(value = {"ROOT", "USER:SELECT"}, mode = SaMode.OR)
public R searchByPage(@RequestBody @Valid SearchUserByPageForm form) {
Map param = BeanUtil.beanToMap(form);
int page = form.getPage();
int length = form.getLength();
int start = (page - 1) * length;
param.put("start", start);
PageUtils pageUtils = userService.searchByPage(param);
return R.ok().put("result", pageUtils);
}
表单验证类
@Data
public class SearchUserByPageForm {
private Integer id;
private String nickName;
@Pattern(regexp = "^[\\u4e00-\\u9fa5]{1,20}$", message = "name姓名内容不正确")
private String name;
// @Pattern(regexp = "^男$|^女$", message = "sex性别格式不正确,只能为男或女")
// private String sex;
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "phone手机号格式不正确")
private String phone;
@Pattern(regexp = "^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$", message = "email邮箱格式不正确")
private String email;
// @NotBlank注解只能用在字符串上,如果不是字符串类型,都可以使用@NotNull
// @NotNull(message = "status状态码不能为空")
@Range(min = 0, max = 1, message = "status状态码不正确,0无效(逻辑删除),1有效")
private Integer status;
@Pattern(regexp = "^ASC$|^DESC$", message = "order排序字段不正确,只能为ASC(升序)或DESC(降序)")
private String order;
@NotNull(message = "page页码不能为空")
@Min(value = 1, message = "page页码不能小于1")
private Integer page;
@NotNull(message = "length每页长度不能为空")
@Range(min = 10, max = 50, message = "length每页长度不正确,最小10,最大50")
private Integer length;
}
XML
<select id="searchByPage" parameterType="Map" resultType="HashMap">
SELECT u.nick_name AS nickName,
u.id,
ui.name,
ui.phone,
ui.email,
u.status,
u.create_time AS createTime
FROM user u
left JOIN user_info ui ON u.id = ui.user_id
WHERE 1 = 1
<if test="nickName != null and nickName != ''">
AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
</if>
<if test="name != null and name != ''">
AND ui.name LIKE CONCAT('%', #{name}, '%')
</if>
<if test="phone != null and phone != ''">
AND ui.phone = #{phone}
</if>
<if test="email != null and email != ''">
AND ui.email = #{email}
</if>
<if test="status != null ">
AND u.status = #{status}
</if>
<if test="order != null and order != ''">
ORDER BY u.nick_name ${order}
</if>
LIMIT #{length} OFFSET #{start}
</select>

被折叠的 条评论
为什么被折叠?



