基于ssm框架的mybatis pagehelper分页插件的使用

基于ssm框架的mybatis pagehelper分页插件的使用

一、准备阶段

1、软件

eclipse,mysql数据库(用的oracle数据库的dept表的数据),maven。

2、maven环境下搭建好的ssm框架。

二、正题

1、maven的pom.xml中配置pagehelper,引入它的jar包

	    com.github.pagehelper
	    pagehelper
	    4.0.0
	

2、mabatis的主配置文件中配置pagehelper的拦截器
 
	 	
	 		
	 		
	 		
	 		
	 		
	 		
	 		
	 		
 	 		
	 	
	 
3、mybatis的mapper配置文件和接口中要有一个查询所有数据的方法,该怎么写就怎么写。
public interface DeptDAO {
		public List findall()throws Exception;
	}

4、对应的service也要有一个查询所有的方法
public List findall() throws Exception {
		List list=deptdao.findall();
		return list;
	}
5、在action中写一个分页的方法
@RequestMapping(value="/finddept.do")
	public String findByPage1(HttpServletRequest request,
			@RequestParam(required=true,defaultValue="1") Integer pageNo,
			@RequestParam(required=false,defaultValue="3") Integer pageSize)throws Exception{
		PageHelper.startPage(pageNo, pageSize);
		//紧跟着的第一个方法会被分页
		List list=deptservice.findall();
		PageInfo page=new PageInfo(list);
		request.setAttribute("list",list);
		request.setAttribute("page",page);
		return "dept";
	}





6、在浏览器中请求http://localhost:8080/ssm001/finddept.do就可以了
基于ssm框架的mybatis pagehelper分页插件的使用_第1张图片


7、实现简单的页面跳转
我用bootstrap简单的修饰了一下,其实都是超链接。此处只贴table和超链接部分

		
部门编号 部门名称 部门地址 操作
${d.deptno} ${d.dname} ${d.loc} 删除
//是否为首页 首页 上一页 //是否为尾页 下一页 尾页
说实话,pageInfo这个类是真好用,想用的,它里面都有。
差不多就这样了,毕竟不是搞前端的。

三、贴个pagehelper官方文档吧

pagehelper官方文档
有问题留言吧。撤了。





你可能感兴趣的:(ssm框架)