开发者学堂课程【微服务+全栈在线教育实战项目演练(SpringCloud Alibaba+SpringBoot):后台讲师管理模块-分页查询】学习笔记,与课程紧密连接,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/667/detail/11288
后台讲师管理模块-分页查询
讲师分页功能
1.配置mp分页插件(分页插件不能少,只有有了插件,分页效果才会有)
/**
*分页插件
*/
@Bean
public Paginationalnterceptor
paginationlnterceptor() {
return new Paginationlnterceptor();
}
2.编写讲师分页查询接口的方法
@GetMapping( "pageTeacher/{current}/{limit}" ) → current代表当前页, limit代表每页记录数
public R pageListTeacher(@PathVariable long current,
@PathVariable long limit) {
//创建page对象
Page<Eduteacher> pageTeacher = new Page<>( current, limit) → 1代表当前页, 3.代表每页的记录数
/调用方法实现分页
//调用方法的时候,底层封装,把分页所有数据封装到pageTeacher对象里面
teacherService. page(pageTeacher, wrapper: null) :
long total = pageTeacher. getTotal(): //
总数记录
List<Eduteacher> records = pageTeacher. getRecords() : //数据list集合
// Map map = new HashMap () :
// map. put ( "total" , total ) :
// map. put ( "rows" , records) :
// return R. ok(). date(map)
return R. ok()
. date( "total" , total) . date( "rows" , records) :
}
//刷新,点击方法
/eduservice/teacher/pageTeacher/{current}/{limit} ,其中俩个参数当前页current
1 , 每页limit 2 ,然后最后点击Try it out!
查看结果
{
"success": true,
"code": 20000,
"message": "
成功
",
,
"data": {
"total": 13,
"rows" : {
{
"id": "1",
"name": "lucy",
"intro":“高
级讲师简
介",
"carcer": "高
级讲师资历
",
"level": 2,
"avatar":
"http://thirdwx.qlogo.cn/mopen/vi_32/DYAI0gq83eoj0hHXhgJNOTSOFsS4uZs8xlConec aVOB8eIli15m)ZcT4aCicvia7uHEufi
"sort": 1,
"isDeleted": false,
"gmtCreste": "2019-10-30 11 :53:83",
"gmtNodified": "2019-10-30 11:53:03"
},
{
"id": "118939029666469762" ,
"name": "李
刚
upupup",
"intro": "高
级讲师简介1
11" ,
"career":“高
级讲师
111" ,
"level": 2,
"avatar":
http://thfrdwx.qlogo.cn/mmopen/vi_32/DYAI0gq83eoj0hHMXhgJNOTSOFsS4uzs8xlConec aVOB8eIli15xmJZcT4aCicuia7wHEufi
"sort": 2,
"isDeleted": false,
"gmtCreate": "2019-10-30 11:55:19",
"gmtHodified": "2019-12-24 15:44:35"
}