Springoot+Mybatis+Pagehelper+Layui 带参数分页

Springoot+Mybatis+Pagehelper+Layui分页

layui分页

 	<!-- layui -->
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}"  >
	<script th:src="@{/static/layui/layui.js}"></script>


<form  class="layui-form form-horizontal m-t"   action="javascript:void(0);" id="searchForm">
	<div class="form-group" >
		<div class="col-sm-2">
             <select name="merchantname" lay-verify="" lay-search  >
                <option value="">商家</option>
				<option th:each="merchantName:${merchantName}" th:value="${merchantName.id}" th:text="${merchantName.name}"></option>
			</select> 
		</div>
        <div class="col-sm-2">
			<input type="text" class="layui-input" id="startToend" placeholder=" - ">
		</div>
		<div class="col-sm-2">
            <select name="channelcode" lay-verify="">
				<option value="">收款渠道</option>
				<option value="wxpay">微信</option>
				<option value="alipay">支付宝</option>
			</select>
		</div>
		<div class="col-sm-2">
           <select name="orderstatus" lay-verify="">
				<option value="">支付状态</option>
				<option value="2">成功</option>
				<option value="3">失败</option>
				<option value="0">其他</option>
			</select>
		</div>
		<div class="col-sm-4">
	       <label ><a  href="javascript:void(0);" id="searchBtn" class="btn btn-white btn-sm " onclick="load()"><i class="iconfont icon-chaxun"></i>查询</a></label> 
	       <label ><a  th:href="@{/detail/details}" id="refresh" class="btn btn-white btn-sm"   ><i class="iconfont icon-shuaxin"></i> 刷新</a></label>
        </div>
    </div>													
</form>
<!--不带参数的分页  上面可以不考虑 -->
<table  class="layui-table">
	<thead>
		<tr >
			<th>商户系统订单号</th>
			<th>平台订单号/网关流水号</th>
			<th>金额</th>
			<th>支付时间</th>
			<th>支付渠道</th>
			<th>支付状态</th>
			<th>订单类型</th>
		</tr>
	</thead>
	<tbody id="tbody"></tbody>
</table>
<!-- 分页-->
<div id="pager"></div>

<!-- 分页的js代码 -->
<script>
$(function(){
	load();
})
</script>
<script>

function load(pageConf) {
	if (!pageConf) {
        pageConf = {};
        pageConf.pageSize = 10;
        pageConf.currentPage = 1;

    }
    <!-- 不带参数的分页  data里面可以删除参数  只需要page、limit -->
    $.ajax({
    	url:"/api/detail/detailByPage",
        type:"POST",
        data:{
        	merchantname:$("select[name=merchantname]").val(),
        	startToend:$("#startToend").val(),
        	channelcode:$("select[name=channelcode]").val(),
        	orderstatus:$("select[name=orderstatus]").val(),
        	page:pageConf.currentPage,
        	limit:pageConf.pageSize
        },
        dataType:"json",
        success:function (data) {
        	layui.use(['laypage', 'layer'], function(){
        	var laypage = layui.laypage,
        	layer = layui.layer;
            console.log(JSON.stringify(data));
            //分页
            //完整功能
			  laypage.render({
			    elem: 'pager'
			    ,count: data.data.count
			    ,curr: pageConf.currentPage
			    ,limit: pageConf.pageSize
			    ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
			    ,jump: function(obj,first){
					//首次不执行
				    if(!first){
				    pageConf.currentPage=obj.curr;
					pageConf.pageSize=obj.limit;
				      load(pageConf);
				    }
			    }
			  });
			  fillTable(data.data.data);
        	})
        }
    })
}
function fillTable(data) {
	
	//展示数据
    var htmlText="";
    $.each(data,(index,obj)=>{
        htmlText+=`
            <tr>
        	 <td>${obj.order_code}</td>
            <td>${obj.gateway_order_code}</td>
            <td>${obj.receipt_amount}</td>
            <td>${obj.pay_time}</td>
			<td>${obj.channel_code=='wxpay'?'微信':(obj.channel_code=='alipay'?'支付宝':'其它')}</td>
            <td>${obj.order_status==1?'待支付':(obj.order_status==2?'成功':(obj.order_status==3?'失败':(obj.order_status==4?'部分退款':'全部退款')))}</td>
            <td>${obj.order_type==1?'支付':(obj.order_type==2?'退款':'其它')}</td>
            </tr>
        `
    })
    $("#tbody").empty();
    $("#tbody").append(htmlText);
}
</script>

controller

#不带参数的分页只需接收page、limit两个参数
@ResponseBody
	@RequestMapping("/detailByPage")
	public Map<String, Object> detail(@RequestParam(required = false, defaultValue = "0") Integer merchantname,
			@RequestParam(required = false) String startToend, @RequestParam(required = false) String channelcode,
			@RequestParam(required = false, defaultValue = "100") Integer orderstatus, @RequestParam Integer page,
			@RequestParam Integer limit) {
		System.out.println(merchantname + "," + startToend + "," + channelcode + "," + orderstatus);
		Map<String, Object> map = new HashMap<>();
		// List<Map<String, Object>> detailpage = detailsService.findDetailsByPage(page,
		// limit);
		System.out.println(page + "------" + limit);
		String start = "";
		String end = "";
		if (!StringUtils.isBlank(startToend)) {
			String[] str = startToend.split(" - ");
			start = str[0];
			end = str[1];
			System.out.println(start + "," + end);

		}
		List<Map<String, Object>> findDetailsByParam = detailsService.findDetailsByParam(page, limit, merchantname,
				channelcode, orderstatus, start, end);
		System.out.println(findDetailsByParam.size());
		for (Map<String, Object> map1 : findDetailsByParam) {
			System.out.println(map1.get("order_code") + "," + map1.get("gateway_order_code") + ","
					+ map1.get("receipt_amount") + "," + map1.get("pay_time") + "," + map1.get("channel_code") + ","
					+ map1.get("order_status") + "," + map1.get("orderType"));
		}

		PageInfo<Map<String, Object>> pageInfo = new PageInfo<Map<String, Object>>(findDetailsByParam);
		map.put("code", 0);
		map.put("msg", "");
		map.put("count", pageInfo.getTotal());
		map.put("data", pageInfo.getList());
		return map;
	}

service

public List<Map<String, Object>> findDetailsByParam(Integer pageNum, Integer pageSize, int merchantid,
			String channelcode, int orderstatus, String start, String end) {
		PageHelper.startPage(pageNum, pageSize);
		return detailsMapper.selectDetailsByParam(merchantid, channelcode, orderstatus, start, end);
	}

mapper

/**
	 * 
	 * Description: 带参数 分页查询<br/>
	 *
	 * @author lipengfei
	 * @param merchantid
	 *            商户id 页面 商户名称
	 * @param channelcode
	 *            支付方式
	 * @param orderstatus
	 *            订单状态
	 * @param start
	 *            支付时间 开始时间
	 * @param end
	 *            支付时间 结束时间
	 * @return
	 */
	List<Map<String, Object>> selectDetailsByParam(Integer merchantid, String channelcode, Integer orderstatus,
			String start, String end);

mapper.xml

<select id="selectDetailsByParam"  resultType="java.util.Map">
  	SELECT t.order_code,t.gateway_order_code,t.receipt_amount,t.pay_time,t.channel_code,t.order_status,t.order_type  FROM trade_order t
		INNER JOIN merchant_app ma
		ON t.app_id=ma.app_id
		WHERE 1=1
  	<if test="arg0!=0">
  		AND ma.merchant_id=#{arg0}
  	</if>
  	<if test="arg1!=''">
  		AND t.channel_code=#{arg1}
  	</if>
  	<if test="arg2==1||arg2==2||arg2==3||arg2==4||arg2==5">
  		AND t.order_status=#{arg2}
  	</if>
  	<if test="arg2==0">
  		AND t.order_status in (1,4,5)
  	</if>
  	<if test="arg3!='' ">
  		AND t.pay_time BETWEEN #{arg3} AND #{arg4}
  	</if>
</select>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值