基于 HTML、Ajax以及 Mybatis 实现 Web 分页

1.前端 js 文件

<script type="text/javascript">
	
	var currPageNoStr=$("#pageIndex").val();       //当前页数
	var currPageNo = parseInt(currPageNoStr);
	var pageCount=1;                               //总页数
	//直接加载主函数
	$(function(){
		showPage();
	    $("#frontPage").click(front);
	    $("#nextPage").click(next);
	    $("#firstPage").click(goFirst);
	    $("#lastPage").click(goLast);
	});
	
	//用来处理请求成功后,返回订单列表的函数
	function common(data){
		$("#tmAbout").empty();       //清空需要列出的内容
        $.each(data.obj, function (index, content) {
	    $("#tmAbout").append("<div class='col-lg-4'><div class='tm-bg-black-transparent 
tm-about-box'><div class='tm-about-number-container'>"+index+"</div><h3 class='tm-about-
name'>Best Quality</h3><p class='tm-about-description'>"+content.order_url+"</p></div>
</div>");
	     });
	}
	//第一次返回页面
	function showPage(){
		var currPageIndex = {"currPageNo":currPageNo};
		$.ajax({
			url:"/data_miner/order/paging",
			dataType:"json",
			async:false,
			data:currPageIndex,
			type:"post",
			success:function(data){
				/* var orderData = eval(data);         */
				if(data.message=="发生未知错误!"){
					alert("出现错误!");
				}else{
					var countStr = data.message;
					var count = parseInt(countStr);
				    pageCount = Math.ceil(count/9);
					$("#tmAbout").empty();          //清空需要列出的内容
					$.each(data.obj, function (index, content) {
						$("#tmAbout").append("<div class='col-lg-4'><a 
href=http://localhost:8080/data_miner/order?order_id="+content.order_id+"><div class='tm-
bg-black-transparent tm-about-box'><div class='tm-about-number-container'>"+index+"</div>
<h3 class='tm-about-name'>Best Quality</h3><p class='tm-about-
description'>"+content.order_url+"</p></div></a></div>");
		            });   
				}
			},
			error:function(data){
				alert(data.message);
			}
		});
	}
	//上一页
    function front(event){
 		if(currPageNo==1){
 			currPageNo=1;
 		}else{
 			currPageNo--;
 		}
 		var currPageIndex = {"currPageNo":currPageNo};
	  	$.ajax({  
	        type:"POST",  
	        dataType:"json",  
	        url:"/data_miner/order/paging",   //回发到的页面  
	        data:currPageIndex,
	        success: common
	     });
    }
    //下一页
    function next(event){
 		if(currPageNo==pageCount){
 			currPageNo=pageCount;
 		}else{
 			currPageNo++;
 		}
 		var currPageIndex = {"currPageNo":currPageNo};
	  	$.ajax({  
	        type:"POST",  
	        dataType:"json",  
	        url:"/data_miner/order/paging",   //回发到的页面  
	        data:currPageIndex,
	        success: common
	     });
    }
    //首页
    function goFirst(event){
   		currPageNo=1;
   		var currPageIndex = {"currPageNo":currPageNo};
	  	$.ajax({  
	        type:"POST",  
	        dataType:"json",  
	        url:"/data_miner/order/paging",   //回发到的页面  
	        data:currPageIndex,
	        success: common
	     });
    }
    //尾页
    function goLast(event){
   		currPageNo=pageCount;
   		var currPageIndex = {"currPageNo":currPageNo};
	  	$.ajax({  
	        type:"POST",  
	        dataType:"json",  
	        url:"/data_miner/order/paging",   //回发到的页面  
	        data:currPageIndex,
	        success: common
	     });
    }
</script>

2.Controller 层

        @Autowired
	private OrderService orderService;
	
	/*
	 * 分页功能
	 */
	@RequestMapping("paging")
	public @ResponseBody Response orderList(Integer currPageNo) {
		Response re = null;
		currPageNo = (currPageNo-1)*9;
		re = orderService.orderList(currPageNo);
		return re;
	}

3.Service 层

        @Autowired
	private OrderMapper orderMapper;
	
	/*
	 * 订单分页以及获取未完成的订单总数
	 */
	public Response orderList(Integer currPageNo) {
		Response re = new Response();
		try {
			List<Order> list = orderMapper.getOrdersJudgeFlag(currPageNo);
			int countPage = orderMapper.countOrdersJudgeFlag();
			String countPageStr = Integer.toString(countPage);
			re.setFlag(true);
			re.setMessage(countPageStr);
			re.setObj(list);
		} catch (Exception e) {
			re.setFlag(false);
			re.setMessage("发生未知错误!");
			re.setObj(null);
			e.printStackTrace();
		}
		return re;
	}

4.Mapper 层

int countOrdersJudgeFlag()throws Exception;

List<Order> getOrdersJudgeFlag(@Param(value="currPageNo") Integer currPageNo)throws 
Exception;

5.xml 文件

  <select id="countOrdersJudgeFlag" resultType="java.lang.Integer">
  	select count(*) from `order` where order_flag=0
  </select>

  <select id="getOrdersJudgeFlag" parameterType="java.lang.Integer" 
resultType="com.data_miner.entity.Order">
  	select * from `order` where order_received=0 limit ${currPageNo},9
  </select>

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值