mybatis分页插件使用案例(前端bootstrap)

1.原因
看了http://blog.csdn.net/u012728960/article/details/50791343这篇文章感觉mybatis分页插件很有用,就转子了,就自己也写了个demo方便日后查看。
2.效果图
mybatis分页插件使用案例(前端bootstrap)
文章图片

3.maven引入和spring配置
maven

com.github.pagehelper pagehelper 4.1.6 com.github.jsqlparser jsqlparser 0.9.6

spring
dialect=mysql

【mybatis分页插件使用案例(前端bootstrap)】4.controller
package com.xie.test.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import com.alibaba.fastjson.JSON; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.xie.test.service.UserService; import com.xie.test.vo.User; @Controller @RequestMapping("/user") public class UserController {@Autowired public UserService userService; @RequestMapping(value="https://www.it610.com/getUserList") public ModelAndView getUserList(ModelAndView modelAndView,int pageNum){ int pageSize=2; PageHelper.startPage(pageNum, pageSize); //当前页,页面大小 //紧跟着的第一个select方法会被分页 List listUser=userService.getUser(); PageInfo pageInfo=new PageInfo(listUser); modelAndView.addObject("listUser", listUser); modelAndView.addObject("pageInfo", pageInfo); modelAndView.setViewName("showUser"); return modelAndView; } }

5.service
package com.xie.test.ServiceImpl; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.xie.test.dao.IUserDao; import com.xie.test.service.UserService; import com.xie.test.vo.User; @Service public class UserServcieImpl implements UserService{@Autowired public IUserDao userDao; public List getUser() { List user=userDao.queryUser(); return user; } }

6.dao及mapper
dao
package com.xie.test.dao; import java.util.List; import com.xie.test.vo.User; public interface IUserDao {/** * 查询全部人员 * @return */ List queryUser(); }

mapper

7.view(显示酷炫是因为用了bootstrap)
showUser - 锐客网
人员列表
id 名字 年龄 级别
${emp.id } ${emp.name } ${emp.age } ${emp.grade }
当前${pageInfo.pageNum }页,总共${pageInfo.pages }页,总共${pageInfo.total }条记录

8.ajax+分页
onclick中的ajaxMethod方法即为调用ajax方法
//分页测试 function showPage(valueA,valueB){ var str="" str+=""+ ""+ "当前"+pageInfo.pageNum +"页,总共"+pageInfo.pages +"页,总共"+pageInfo.total+"条记录"+ ""+ ""+ ""; $("#xie").html(str); }

    推荐阅读