提示:文章如有错误的地方请指出,以免误人子弟!
提示:以下是本篇文章正文内容,下面案例可供参考
一、导入maven jar包,mysql,mybatis自行引入
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.1</version>
</dependency>
二、application.yml 配置
- mybatis
mybatis:
configuration:
cache-enabled: false
map-underscore-to-camel-case: true
# mapper.xml 文件的匹配规则
mapper-locations: classpath:mapping/**/*Mapper.xml
# 实体类所在的包
type-aliases-package: com.onlyoa.common.entity
- pagehelper
pagehelper:
# 数据库
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
page-size-zero: true
三、上代码
具体sql,mapper,service怎么分层的,注解使用,请自行百度,这里不过多描述!
- sql
<!-- 分页查询全部人员信息 -->
<select id="queryClassInfoList" resultType="com.wwwh.onlyone.common.entity.doo.SysClassInfoDO">
select * from class where id = #{classId}
</select>
- mapper
@Param注解的作用是给参数命名,参数命名后就能根据名字得到参数值,正确的将参数传入sql语句中。 Page 是ArrayList 的子类
/**
* description: 分页查询班级信息
*
* @param status 人员状态
* @return com.github.pagehelper.Page<com.wwwh.onlyone.common.entity.doo.SysClassInfoDO>
* @author Mr.Tiger
*/
Page<SysClassInfoDO> queryClassInfoList(@Param("classId")Integer classId);
- service
/**
* description: 分页查询班级信息
*
* @param pageNo 起始页
* @param pageSize 每页数量
* @param classId 班级id
* @return com.github.pagehelper.PageInfo<com.wwwh.onlyone.common.entity.doo.SysClassInfoDO>
* @author Mr.Tiger
*/
PageInfo<SysClassInfoDO> queryClassInfoList(int pageNo, int pageSize, Integer classId);
- serviceImpl (接口实现类)
@Override
public PageInfo<SysEmpInfoDO> pageQueryEmpInfoLists(int pageNo, int pageSize, Integer classId) {
//开始分页
PageHelper.startPage(pageNo, pageSize);
//查询数据
Page<SysEmpInfoDO> list = sysEmpInfoMapper.queryEmpInfoList(classId);
//放入数据
return new PageInfo<SysEmpInfoDO>(list);
}
- controller层就不写了,直接@Autowired用就好了!
希望对你有所帮助!