Springoot+Mybatis+Pagehelper+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>
< 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 < > ( ) ;
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
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>