<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>4.1.6</version> </dependency>
<?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">
<!--
namespace:名称空间
-->
<mapper namespace="com.mapper.UserMapper">
</mapper>
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <typeAliases> <package name="com.pojo"/> </typeAliases> <!--mybatis核心配置,配置分页插件--> <plugins> <plugin interceptor="com.github.pagehelper.PageHelper"> <property name="dialect" value="mysql"/> <!-- 启用分页参数的合理化: 如果页码小于1, 则默认查询第一页 大于最大页码, 则默认查询最后一页 --> <property name="reasonable" value="true"/> </plugin> </plugins> <environments default="development"> <environment id="development"> <transactionManager type="JDBC"/> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql:///db?useSSL=false"/> <property name="username" value="root"/> <property name="password" value="root"/> </dataSource> </environment> </environments> <mappers> <!--扫描mapper--> <package name="com.mapper"/> </mappers> </configuration>
@Override public PageInfo selectByPage(int currentPage, int pageSize, Brand brand) { SqlSession sqlSession = SqlSessionFactoryUtils.getSqlSession(); BrandMapper brandMapper = sqlSession.getMapper(BrandMapper.class); PageHelper.startPage(currentPage,pageSize); List<Brand> list = brandMapper.selectByPage(brand); PageInfo<Brand> pageInfo = new PageInfo<>(list); return pageInfo; }