freemark動態載入列表資料
阿新 • • 發佈:2019-02-08
1.ftl頁面中 <table class="table table-striped table-hover table-bordered" name="record" id="editable-sample"> </table> function pay_details(game_id){ $("[name='record']").html(""); //獲取上面table的name,清空table $.post('${basePath}/agency/pay_details.shtml',{ "game_id":game_id },function(result){ var html_=""; var html__=""; html_=html_+ "<thead >"+ "<tr>"+ "<th>遊戲ID</th>"+ "<th>充值人</th>"+ "<th>遊戲使用者名稱</th>"+ "<th>金額</th>"+ "<th>兌換率</th>"+ "<th>充值金幣</th>"+ "<th>訂單號</th>"+ "<th>充值時間</th>"+ "<th>支付狀態</th>"+ "<th>充值狀態</th>"+ "<th>充值型別</th>"+ "</tr>"+ "</thead>"; $.each(result, function(idx, obj) { html__=html__+ "<tr>"+ "<td>"+obj.GameID+"</td>"+ "<td>"+obj.TrueName+"</td>"+ "<td>"+obj.UserName+"</td>"+ "<td>"+obj.PayMoney+"</td>"+ "<td>"+obj.ExchangeRate+"</td>"+ "<td>"+obj.InMoney+"</td>"+ "<td>"+obj.OrderID+"</td>"+ "<td>"+obj.AddTime+"</td>"+ "<td>"+(obj.PaySuccess=='true'? '已支付' :'未支付')+"</td>"+ "<td>"+(obj.InSuccess=='true'? '已充值' : '未充值')+"</td>"+ "<td>"+obj.TypeInfo+"</td>"+ "</tr>"; }); $("[name='record']").html(html_+html__);//把固定行和動態遍歷的行載入到table中 }); } 2.controller中提供List資料 @RequestMapping(value = "pay_details", method = RequestMethod.POST) @ResponseBody public List<Map<String, String>> pay_details(HttpServletRequest request) { List<Map<String, String>> si = new ArrayList<Map<String, String>>(); if (request.getParameter("game_id") != null && request.getParameter("game_id") != "") { // 傳送 POST 請求 String game_id = request.getParameter("game_id").toString(); String sr = RequestService.sendPost(InterfaceAddressConfig.get("GetOrderList"), "game_id="+ game_id + "&pageSize=900000&pageIndex=1");// 請求充值成功的conditions=1為充值成功,每頁90w條 HashMap<String, String> stringToMap = StringToMap.StringToMap(sr); if (!"[]".equals(stringToMap.get("list").toString())) { String replace = stringToMap.get("list").toString().replace("[", "").replace("]", ""); String[] arr = replace.split("\\},\\{"); List<String> list = java.util.Arrays.asList(arr); for (String list_ : list) { String lists = "{" + list_.replace("{", "").replace("}", "") + "}"; System.out.println(lists); HashMap<String, String> itemMap = StringToMap.StringToMap(lists); si.add(itemMap); } } } return si; }