前端传递参数,当前页和每页条数
{
"current": 1,
"size": 20
}
接口接收参数,可以通过自定义的实体类继承PageDto
@Data
public class PageDto {
@ApiModelProperty(value = "当前页")
private long current;
@ApiModelProperty(value = "每页条数")
private long size;
}
自定义实体类,继承PageDto
@Data
@ApiModel
public class OfaUserSearchVo extends PageDto{
@ApiModelProperty(value = "账号")
private String userName;
@ApiModelProperty(value = "手机号码")
private String mobile;
@ApiModelProperty(value = "电子邮件")
private String email;
}
mapper定义,Page
对象需要放在第一个参数
public interface OfaUserMapper extends BaseMapper<OfaUser> {
IPage<OfaUserVo> selectPageVo(Page page,@Param("params") Map params);
}
xml编写,等同于编写一个普通 list 查询,会自动分页:
<select id="selectPageVo" resultMap="userVoResult">
select u.*,r.role_name,r.id as role_id,r.remark from ofa_user u LEFT JOIN ofa_user_role_ref rr on u.id=rr.user_id LEFT JOIN ofa_role r on rr.role_id =r.id
<where>
<if test="params.userName!=null and params.userName != ''">
u.user_name like #{params.userName}
</if>
<if test="params.mobile!=null and params.mobile != ''">
and u.mobile like #{params.mobile}
</if>
<if test="params.email!=null and params.email != ''">
and u.email like #{params.email}
</if>
</where>
</select>
接口调用:
@ApiOperation(value = "查询用户列表", response = OfaUserVo.class)
@GetMapping("/user/list")
public RestData<IPage<OfaUserVo>> list(OfaUserSearchVo searchVo) {
Page<OfaUserVo> ofaUserVoPage = new Page<>(searchVo.getCurrent(), searchVo.getSize());
IPage<OfaUserVo> data = ofaUserMapper.selectPageVo(ofaUserVoPage, param);
return addRestData(data);
}
接口返回:
{
"code": 200,
"data": {
"records": [
{
"id": "392359587803045888",
"userName": "zhangrenlong",
"mobile": null,
"email": null,
"enable": 1,
"userType": 2,
"lastLoginIp": "119.130.207.97",
"lastLoginTime": "2019-11-14 14:23:22",
"createBy": "sdswhg_admin",
"createTime": "2019-11-14 14:18:01",
"updateTime": "2019-11-14 14:20:30",
"orgId": "392358546231533568"
},
{
"id": "392361863018639360",
"userName": "liuzhibin",
"mobile": null,
"email": null,
"enable": 1,
"userType": 2,
"lastLoginIp": null,
"lastLoginTime": null,
"createBy": "sdswhg_admin",
"createTime": "2019-11-14 14:27:04",
"updateTime": "2019-11-14 14:27:04",
"orgId": "392358546231533568",
"roleList": [ ]
},
{
"id": "392361977163816960",
"userName": "liangzhirong",
"mobile": null,
"email": null,
"enable": 1,
"userType": 2,
"lastLoginIp": null,
"lastLoginTime": null,
"createBy": "sdswhg_admin",
"createTime": "2019-11-14 14:27:31",
"updateTime": "2019-11-14 14:27:31",
"orgId": "392358546231533568",
"roleList": [ ]
},
{
"id": "392362032858591232",
"userName": "huangweibin",
"mobile": null,
"email": null,
"enable": 1,
"userType": 2,
"lastLoginIp": null,
"lastLoginTime": null,
"createBy": "sdswhg_admin",
"createTime": "2019-11-14 14:27:44",
"updateTime": "2019-11-14 14:27:44",
"orgId": "392358546231533568",
"roleList": [ ]
}
],
"total": "4",
"size": "20",
"current": "1",
"orders": [ ],
"searchCount": true,
"pages": "1"
},
"desc": "操作成功"
}