tlias管理系统--部门管理--分页查询实现
This commit is contained in:
@@ -62,6 +62,9 @@
|
|||||||
<source>11</source>
|
<source>11</source>
|
||||||
<target>11</target>
|
<target>11</target>
|
||||||
<encoding>UTF-8</encoding>
|
<encoding>UTF-8</encoding>
|
||||||
|
<compilerArgs>
|
||||||
|
<arg>-parameters</arg>
|
||||||
|
</compilerArgs>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
@@ -1,7 +1,38 @@
|
|||||||
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.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RequestMapping("/emps")
|
||||||
@RestController
|
@RestController
|
||||||
|
@Slf4j
|
||||||
public class EmpController {
|
public class EmpController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EmpService empService;
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public Result page(
|
||||||
|
@RequestParam(defaultValue = "1") Integer page
|
||||||
|
,@RequestParam(defaultValue = "10") Integer pageSize){
|
||||||
|
/*if (page == null) {
|
||||||
|
page = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pageSize == null) {
|
||||||
|
pageSize = 10;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
log.info("分页查询:{},{}",page,pageSize);
|
||||||
|
//调用员工业务层的分页查询功能
|
||||||
|
PageBean pageBean = empService.page(page,pageSize);
|
||||||
|
return Result.success(pageBean);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,21 @@
|
|||||||
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 {
|
||||||
|
/**
|
||||||
|
* 查询总记录数
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Select("select count(*) from emp")
|
||||||
|
Long getTotal();
|
||||||
|
|
||||||
|
@Select("select * from emp limit #{startIndex},#{pageSize}")
|
||||||
|
List<Emp> getPageList(int startIndex,int pageSize);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
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,13 @@
|
|||||||
package com.inmind.service;
|
package com.inmind.service;
|
||||||
|
|
||||||
|
import com.inmind.pojo.PageBean;
|
||||||
|
|
||||||
public interface EmpService {
|
public interface EmpService {
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
* @param page
|
||||||
|
* @param pageSize
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
PageBean page(Integer page, Integer pageSize);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,43 @@
|
|||||||
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
* @param page 页码
|
||||||
|
* @param pageSize 每页显示条数
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageBean page(Integer page, Integer pageSize) {
|
||||||
|
//1.获取总记录数
|
||||||
|
Long total = empMapper.getTotal();
|
||||||
|
//2.获取当前页的数据列表
|
||||||
|
/*
|
||||||
|
-- 分页查询 :select * from emp limit 参数1 参数2
|
||||||
|
-- 参数1:起始索引 就是(页码-1)*每页显示的记录数
|
||||||
|
-- 参数2:查询返回的记录数 就是每页显示的记录数
|
||||||
|
*/
|
||||||
|
int startIndex = (page - 1)* pageSize;
|
||||||
|
List<Emp> rows = empMapper.getPageList(startIndex,pageSize);
|
||||||
|
//3.封装成分页查询结果,并返回
|
||||||
|
/*PageBean pageBean = new PageBean();
|
||||||
|
pageBean.setRows(rows);
|
||||||
|
pageBean.setTotal(total);
|
||||||
|
return pageBean;*/
|
||||||
|
return new PageBean(total, rows);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user