参考:
http://www.cnblogs.com/landeanfen/p/4976838.html
http://blog.csdn.net/wzj0808/article/details/59104035
本来bootstrap-table就有服务端分页,这次介绍的是使用ssm框架结合PageHelper结合bootstrap-table来分页,PageHelper和bootstrap-table的引入我就不再介绍了.
public interface DormitoryMapper { ListgetDormitoryliveinfo(@Param("strDormitorynumber") String strDormitorynumber, @Param("strRoomnumber") String strRoomnumber); }
public interface DormitoryService { //分页 PageInfogetDormitoryliveinfo(String strDormitorynumber,String strRoomnumber,Integer currentPage, Integer pageSize); }
@Service public class DormitoryServiceImpl implements DormitoryService {
@Autowired DormitoryMapper dormitoryMapper;
@Override public PageInfogetDormitoryliveinfo(String strDormitorynumber, String strRoomnumber,Integer currentPage,Integer pageSize) { // TODO Auto-generated method stub PageHelper.startPage(currentPage,pageSize); List list = dormitoryMapper.getDormitoryliveinfo(strDormitorynumber, strRoomnumber); PageInfo pageInfo = new PageInfo<>(list); return pageInfo; }}
@Controller @RequestMapping("/dormitory") public class DormitoryController {
@Autowired DormitoryService dormitoryService;
@RequestMapping("/getDormitoryliveinfo") @ResponseBody public PageInfogetDormitoryliveinfo(String strDormitorynumber,String strRoomnumber,Integer currentPage,Integer pageSize){ PageInfo pageInfo = dormitoryService.getDormitoryliveinfo(strDormitorynumber, strRoomnumber,currentPage,pageSize); return pageInfo; }}
$('#tabletest').bootstrapTable({ columns: [{ field: 'username', title: '用户名', }, { field: 'name', title: '姓名', }, { field: 'phone', title: '联系方式', },{ field: 'email', title: '邮件', },{ field: 'dept.dept', title: '部门', },{ field: 'dormitory.dormitory_number', title: '宿舍楼', },{ field: 'dormitory.room_number', title: '房间号', },{ field: 'dormitory.tnumber', title: '总数', },{ field: 'dormitory.left_number', title: '剩余数量', } ], showToggle:true, showRefresh: true, locale:'zh-CN',//中文支持 //页面需要展示的列,后端交互对象的属性 pagination: true, //开启分页 sidePagination: 'server', pageNumber: 1,//默认加载页 pageSize: 10,//每页数据 pageList: [5,10,15,20],//可选的每页数据 queryParamsType:'',//queryParamsType的默认值为 'limit' ,在默认情况下 传给服务端的参数为:offset,limit,sort //设置为 '' 在这种情况下传给服务器的参数为:pageSize,pageNumber */ queryParams: function (params) { return { strDormitorynumber: strDormitorynumber, strRoomnumber:strRoomnumber, currentPage:params.pageNumber, pageSize:params.pageSize } },//请求服务器数据时的参数 url: '/getDormitoryliveinfo', //服务器数据的加载地址 responseHandler:function(res){ //在ajax获取到数据,渲染表格之前,修改数据源 var nres = []; nres.push({total:res.total,rows:res.list}); return nres[0]; } });说明:
responseHandler:function(res){ //在ajax获取到数据,渲染表格之前,修改数据源 var nres = []; nres.push({total:res.total,rows:res.list}); return nres[0]; } });在上面这个处理函数中,挑选出了total和rows,这里res.list的list名,是在Impl实现类中的List