导入依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.3</version>
</dependency>
service层
package com.project.service;
import com.github.pagehelper.PageInfo;
import com.project.bean.userBean;
public interface userService {
PageInfo<userBean> selectAll(int pageNO, int pageSize);
}
service实现类
package com.project.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.userBean;
import com.project.service.userService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional
public class userServiceImpl implements userService {
@Resource
private com.project.dao.userDao userDao;
@Override
public PageInfo<userBean> selectAll(int pageNO, int pageSize) {
PageHelper.startPage(pageNO,pageSize);
PageInfo<userBean>pageInfo=PageInfo.of(userDao.selectAll());
return pageInfo;
}
}
dao层
package com.project.dao;
import com.project.bean.userBean;
import java.util.List;
public interface userDao {
//分页显示所有用户信息
List<userBean> selectAll();
}
xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.project.dao.userDao">
<resultMap id="userMap" type="com.project.bean.userBean">
<id column="user_id" property="userId"/>
<result column="user_name" property="userName"/>
<result column="user_pwd" property="userPwd"/>
<result column="user_role" property="role"/>
<result column="user_realName" property="realName"/>
</resultMap>
<select id="selectAll" resultMap="userMap">
select * from user_info
</select>
</mapper>