(1)pagehelper是什么? 针对Mybatis提供分页插件,将分页查询简化 (2)依赖配置 pagehelper (3)配置插件plugin 配置方法有两种
1 : mybatis核心配置文件,在application中引入 mybatis核心配置文件2 : 在application中配置同时在spring中引入mybatis的配置
<!-- session工厂--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <!-- com.wzx.domain.Person person--> <property name="typeAliasesPackage" value="com.wzx.domain"/> 这里引入配置文件 ==>><property name="configLocation" value="classpath:SqlMapConfig.xml"/> </bean>3.使用插件
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:applicationContext.xml") public class TestPageHelper { @Autowired private IDepartmentService departmentService; private static final Logger log = LoggerFactory.getLogger(TestPageHelper.class); @Test public void test01(){ //调用分页插件只要两行代码 PageHelper.startPage(1,10);//参1:单前页数 参2 每页记录数 //我们只需要做一个最简单的查询 List<Department> list = departmentService.findAllDepartments(); //将查询结果放入PageInfo中 PageInfo<Department> pageInfo = new PageInfo<>(list); log.info("test01 pageInfo="+pageInfo); } }