使用分页查询员工数据
EmpBasicController
@GetMapping("/")
public RespPageBean getEmployeeByPage(
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size,
Employee employee, Date[] beginDateScope) {
return employeeService.getEmployeeByPage(page, size, employee, beginDateScope);
}
EmployService
public RespPageBean getEmployeeByPage(Integer page, Integer size,
Employee employee, Date[] beginDateScope) {
if (page != null && size != null) {
page = (page - 1) * size;
}
List<Employee> data = employeeMapper.getEmployeeByPage(page, size, employee, beginDateScope);
Long total = employeeMapper.getTotal(employee, beginDateScope);
RespPageBean bean = new RespPageBean();
bean.setData(data);
bean.setTotal(total);
return bean;
}
Mapper
select e.*,p.`id` as pid,p.`name` as pname,n.`id` as nid,n.`name` as nname,d.`id` as did,
d.`name` as dname,j.`id` as jid,j.`name` as jname,pos.`id` as posid,pos.`name` as posname
from employee e,nation n,politicsstatus p,department d,joblevel j,position pos
where e.`nationId`=n.`id` and e.`politicId`=p.`id` and e.`departmentId`=d.`id`
and e.`jobLevelId`=j.`id` and e.`posId`=pos.`id`
limit 2,10
<select id="getEmployeeByPage" resultMap="AllEmployeeInfo">
select e.*,p.`id` as pid,p.`name` as pname,n.`id` as nid,n.`name` as nname,d.`id` as did,d.`name` as
dname,j.`id` as jid,j.`name` as jname,pos.`id` as posid,pos.`name` as posname
from employee e,nation
n,politicsstatus p,department d,joblevel j,position pos where e.`nationId`=n.`id` and e.`politicId`=p.`id` and
e.`departmentId`=d.`id` and e.`jobLevelId`=j.`id` and e.`posId`=pos.`id`
<if test="emp.name !=null and emp.name!=''">
and e.name like concat('%',#{emp.name},'%')
</if>
<if test="emp.politicId !=null">
and e.politicId =#{emp.politicId}
</if>
<if test="emp.nationId !=null">
and e.nationId =#{emp.nationId}
</if>
<if test="emp.departmentId !=null">
and e.departmentId =#{emp.departmentId}
</if>
<if test="emp.jobLevelId !=null">
and e.jobLevelId =#{emp.jobLevelId}
</if>
<if test="emp.engageForm !=null and emp.engageForm!=''">
and e.engageForm =#{emp.engageForm}
</if>
<if test="emp.posId !=null">
and e.posId =#{emp.posId}
</if>
<if test="beginDateScope !=null">
and e.beginDate between #{beginDateScope[0]} and #{beginDateScope[1]}
</if>
<if test="page !=null and size!=null">
limit #{page},#{size}
</if>
</select>
前端
前端是个表。
所以如果以后用到表的时候,再来这里看吧。
别忘了实现日期的格式过滤