1模糊查询 like
还是老样子先导入jar包,建立我们的类和接口,还有导入日志文件
然后就是mapper了
测试
2.分页插件
回顾分页的sql语句
1. select * from 表名 limit (page-1)*pageSize,pageSize;
page:当前要显示的页码。
pageSize: 每页显示的条数。
2.显示第一页数据 每页显示五条.
select * from 表名 limit 0,5;
(1) 引入相关的pageHelper依赖(还是放到jar包里)
<!--分页插件的依赖-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.11</version>
</dependency>
(2) 加入拦截(在mybatis中加入)
<plugins>
<!-- com.github.pagehelper为PageHelper类所在包名 -->
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<!-- 使用下面的方式配置参数,后面会有所有的参数介绍 -->
<property name="param1" value="value1"/>
</plugin>
</plugins>
mapper中的方法
(3)测试
@Test
public void testUpdate3(){
Yuan yuan= session.getMapper(YuanDao.class);
//使用分页功能 request.getParamter("page") request.getParamter("pageSize")
PageHelper.startPage(2,10);
List<Yuan> list = yuanDao.findAll3("老");
//可以把查询的结果封装到PageInfo类中 包含你想要的任何信息
PageInfo<Yuan> pageInfo=new PageInfo<Yuan>(list);
System.out.println("总条数:"+pageInfo.getTotal());
System.out.println("当前页码的数据:"+pageInfo.getList());
}