tlias管理系统-员工分页查询功能实现
This commit is contained in:
@@ -1,7 +1,25 @@
|
|||||||
package com.inmind.controller;
|
package com.inmind.controller;
|
||||||
|
|
||||||
|
import com.inmind.pojo.PageBean;
|
||||||
|
import com.inmind.pojo.Result;
|
||||||
|
import com.inmind.service.EmpService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
@Slf4j
|
||||||
public class EmpController {
|
public class EmpController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EmpService empService;
|
||||||
|
|
||||||
|
@GetMapping("/emps")
|
||||||
|
public Result page(Integer page,Integer pageSize){
|
||||||
|
log.info("分页查询,参数page :{};pageSize:{}",page,pageSize);
|
||||||
|
//调用业务层获取分页结果数据
|
||||||
|
PageBean pageBean = empService.page(page,pageSize);
|
||||||
|
return Result.success(pageBean);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,24 @@
|
|||||||
package com.inmind.mapper;
|
package com.inmind.mapper;
|
||||||
|
|
||||||
|
import com.inmind.pojo.Emp;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface EmpMapper {
|
public interface EmpMapper {
|
||||||
|
//查询总记录数
|
||||||
|
@Select("select count(*) from emp")
|
||||||
|
Long getTotal();
|
||||||
|
|
||||||
|
/*
|
||||||
|
分页查询 limit
|
||||||
|
参数1:起始索引 就是 (页码-1)*每页展示的记录数
|
||||||
|
参数2:查询返回记录数 就是 每页展示的记录数
|
||||||
|
*/
|
||||||
|
//分页查询获取员工列表数据
|
||||||
|
@Select("select * from emp limit #{startIndex},#{pageSize};")
|
||||||
|
List<Emp> getPageList(Integer startIndex,Integer pageSize);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.inmind.pojo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/*
|
||||||
|
分页查询结果封装类
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class PageBean {
|
||||||
|
private Long total;//总记录数
|
||||||
|
private List rows;//数据列表
|
||||||
|
}
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
package com.inmind.service;
|
package com.inmind.service;
|
||||||
|
|
||||||
|
import com.inmind.pojo.PageBean;
|
||||||
|
|
||||||
public interface EmpService {
|
public interface EmpService {
|
||||||
|
//分页查询员工列表数据
|
||||||
|
PageBean page(Integer page, Integer pageSize);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,32 @@
|
|||||||
package com.inmind.service.impl;
|
package com.inmind.service.impl;
|
||||||
|
|
||||||
|
import com.inmind.mapper.EmpMapper;
|
||||||
|
import com.inmind.pojo.Emp;
|
||||||
|
import com.inmind.pojo.PageBean;
|
||||||
import com.inmind.service.EmpService;
|
import com.inmind.service.EmpService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class EmpServiceImpl implements EmpService {
|
public class EmpServiceImpl implements EmpService {
|
||||||
|
@Autowired
|
||||||
|
private EmpMapper empMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageBean page(Integer page, Integer pageSize) {
|
||||||
|
//1.调用mapper获取总记录数和分页的员工列表数据
|
||||||
|
Long total = empMapper.getTotal();
|
||||||
|
/*
|
||||||
|
分页查询 limit
|
||||||
|
参数1:起始索引 就是 (页码-1)*每页展示的记录数
|
||||||
|
参数2:查询返回记录数 就是 每页展示的记录数
|
||||||
|
*/
|
||||||
|
int startIndex = (page - 1)*pageSize;
|
||||||
|
List<Emp> empList = empMapper.getPageList(startIndex,pageSize);
|
||||||
|
//2.封装pagebean对象
|
||||||
|
PageBean pageBean = new PageBean(total, empList);
|
||||||
|
return pageBean;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user