您好,登錄后才能下訂單哦!
1.dao層
MyBatis映射
mapper.xml中
<select id="getTcdt" parameterType="com.ls.entity.Mydata" resultMap="BaseResultMap"> select * from TB_COMMUNICATION_DEVICE_TBL ORDER BY ${ordername} ${order} </select>
mapper.java中
public List<Tb_communication_device_tbl> getTcdt(Mydata data);//分頁(yè)查詢
2.業(yè)務(wù)層service
/** * 實(shí)現(xiàn)分頁(yè)顯示 */ @Override public JSONObject getTcdt(Mydata data) { // TODO Auto-generated method stub JSONObject result=null; List<Tb_communication_device_tbl> md=tbdao.getTcdt(data); List<Tb_communication_device_tbl> resultList = new ArrayList<Tb_communication_device_tbl>() ; //判斷前臺(tái)頁(yè)面?zhèn)骰氐闹凳遣皇强詹皇沁M(jìn)行條件模糊查詢 if(null!=data.getStationNr() && !data.getStationNr().trim().equals("")||data.getWellDbk()!=null&&data.getWellDbk().trim().equals("")){ for(Tb_communication_device_tbl user :md){ if(user.getStationNr().indexOf(data.getStationNr()) >= 0){ resultList.add(user); } } }else{ resultList = md; } //獲取分頁(yè)數(shù)據(jù) int pageNumber = null!=data.getDangqian() ? Integer.parseInt(data.getDangqian()) : 0; int pageSize = null!=data.getFrist() ? Integer.parseInt(data.getFrist()) : 10; int start = (pageNumber) * pageSize;//計(jì)算開(kāi)始記錄數(shù) int end = start+pageSize;//計(jì)算結(jié)束記錄數(shù) md= new ArrayList<Tb_communication_device_tbl>() ; for(int i=start;i<end && i<resultList.size();i++){ Tb_communication_device_tbl e=resultList.get(i); md.add(e); } int total=0; //存儲(chǔ)值map中 Map<String, Object> map=new HashMap<String, Object>(); SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd"); //實(shí)現(xiàn)數(shù)據(jù)類(lèi)型轉(zhuǎn)換主要是日期類(lèi)型轉(zhuǎn)換成字符串 List<Mydate> list=new ArrayList<>(); for (int i = 0; i < md.size(); i++) { Mydate my=new Mydate(); my.setAlarmVoltage(md.get(i).getAlarmVoltage()); my.setBatteryElectricQty(md.get(i).getBatteryElectricQty()); my.setInstallDate(sf.format(md.get(i).getInstallDate())); //my(md.get(i))); my.setDeviceClass((md.get(i).getDeviceClass())); my.setLevelElevationAlarm((md.get(i).getLevelElevationAlarm())); my.setNewWellDbk(md.get(i).getNewWellDbk()); my.setOperationDate(sf.format(md.get(i).getOperationDate())); my.setReadoutFrequency(md.get(i).getReadoutFrequency()); my.setRemark(md.get(i).getRemark()); my.setReturenValueBln(md.get(i).getReturenValueBln()); /*my.setSendingcycle(md.get(i).getSendingcycle()); my.setSendingstarttime(md.get(i).getSendingstarttime());*/ my.setShowingBln(md.get(i).getShowingBln()); my.setSignalAlarm(md.get(i).getSignalAlarm()); my.setSimcardNr(md.get(i).getSimcardNr()); my.setStationNr(md.get(i).getStationNr()); my.setTransmittingFrequency(md.get(i).getTransmittingFrequency()); my.setUserId(md.get(i).getUserId()); my.setWaterTemperatureAlarm(md.get(i).getWaterTemperatureAlarm()); my.setWellDbk(md.get(i).getWellDbk()); my.setWorkingStatus(md.get(i).getWorkingStatus()); list.add(my); } map.put("total", resultList.size()); map.put("rows", list); //存入返回值中 result=JSONObject.fromObject(map); return result; }
3.action層
public String execute(){ String pageNO=null; String pageSize=null; if(offset==null||limit==null){ pageNO ="0"; pageSize="10"; }else{ pageNO =offset; pageSize=limit; } //給對(duì)象賦值 Mydata data=new Mydata(); data.setDangqian(pageNO); data.setFrist(pageSize); //System.out.println(wells); data.setStationNr(departmentname); data.setWellDbk(wells); data.setOrder(order); //點(diǎn)擊列頭獲取屬性因?yàn)閷傩院蛿?shù)據(jù)庫(kù)列名不一樣所以排序要進(jìn)行修改列名 if(ordername==null){ data.setOrdername("STATION_NR"); } if(ordername!=null){ if(ordername.equals("deviceClass")){ data.setOrdername("DEVICE_CLASS"); } if(ordername.equals("stationNr")){ data.setOrdername("STATION_NR"); } if(ordername.equals("batteryElectricQty")){ data.setOrdername("BATTERY_ELECTRIC_QTY"); } if(ordername.equals("simcardNr")){ data.setOrdername("SIMCARD_NR"); } if(ordername.equals("wellDbk")){ data.setOrdername("WELL_DBK"); } if(ordername.equals("installDate")){ data.setOrdername("INSTALL_DATE"); } } result=tb_communication_device_tblservice.getTcdt(data); list=tB_MONITOR_WELL_TBLservice.getTmwt();//獲取外鍵的值 Map<String, Object> map=ActionContext.getContext().getSession(); map.put("list", list);// map.put("offset2", offset); map.put("limit1", limit); return SUCCESS; }
js文件
var TableInit = function () { var oTableInit = new Object(); var stationNr=null; var stationNr2=null; var arr=new Array(); var arr1=new Array(); //定義查詢方法 Array.prototype.indexOf = function(val) { for (var i = 0; i < this.length; i++) { if (this[i] == val) return i; } return -1; }; Array.prototype.remove = function(val) { var index = this.indexOf(val); if (index > -1) { this.splice(index, 1); } }; //初始化Table oTableInit.Init = function () { $('#tb_departments').bootstrapTable({ url: 'tcdtaction', //請(qǐng)求后臺(tái)的URL(*) method: 'get', //請(qǐng)求方式(*) toolbar: '#toolbar', //工具按鈕用哪個(gè)容器 striped: false, //是否顯示行間隔色 cache: false, //是否使用緩存,默認(rèn)為true,所以一般情況下需要設(shè)置一下這個(gè)屬性(*) pagination: true, //是否顯示分頁(yè)(*) sortable: true, //是否啟用排序 sortOrder: "asc", //排序方式 queryParams: oTableInit.queryParams, //傳遞參數(shù)(*) sidePagination: "server", //分頁(yè)方式:client客戶端分頁(yè),server服務(wù)端分頁(yè)(*) pageNumber: 1, //初始化加載第一頁(yè),默認(rèn)第一頁(yè) pageSize: 10, //每頁(yè)的記錄行數(shù)(*) pageList: [10, 25, 50, 100], //可供選擇的每頁(yè)的行數(shù)(*) search: false, //是否顯示表格搜索,此搜索是客戶端搜索,不會(huì)進(jìn)服務(wù)端,所以,個(gè)人感覺(jué)意義不大 strictSearch: false,//設(shè)置為 true啟用 全匹配搜索,否則為模糊搜索 // showExport表示是否顯示導(dǎo)出的按鈕,exportDataType表示導(dǎo)出的模式是當(dāng)前頁(yè)、所有數(shù)據(jù)還是選中數(shù)據(jù)。 sortable:true,//設(shè)置為false 將禁止所有列的排序 searchOnEnterKey:true,//設(shè)置為 true時(shí),按回車(chē)觸發(fā)搜索方法,否則自動(dòng)觸發(fā)搜索方法 showColumns: true, //是否顯示所有的列 showRefresh: true, //是否顯示刷新按鈕 showExport: true,//是否顯示導(dǎo)出 showpaginationswitch:true,//是否顯示 數(shù)據(jù)條數(shù)選擇框 minimumCountColumns: 2, //最少允許的列數(shù) clickToSelect: true, //是否啟用點(diǎn)擊選中行 height: 532, //行高,如果沒(méi)有設(shè)置height屬性,表格自動(dòng)根據(jù)記錄條數(shù)覺(jué)得表格高度 uniqueId: "id", //每一行的唯一標(biāo)識(shí),一般為主鍵列 showToggle: true, //是否顯示詳細(xì)視圖和列表視圖的切換按鈕 cardView: false, //是否顯示詳細(xì)視圖 detailView: true, //是否顯示父子表 exportTypes: ['csv','txt','xml'], exportDataType: "basic", columns: [{ align: "center", checkbox: true }, { field: 'stationNr', title: '站號(hào)', align: "center", sortable: true, editable: true }, { field: 'deviceClass', title: '通訊設(shè)備類(lèi)型', align: "center", sortable: true, editable: true }, { field: 'batteryElectricQty', title: '電池電量', align: "center", sortable: true, editable: true }, { field: 'simcardNr', title: 'SIM卡號(hào)', align: "center", sortable: true, editable: true }, { field: 'wellDbk', title: '統(tǒng)一編號(hào)', sortable: true, align: "center", editable: true }, { field: 'installDate', title: '安裝日期', sortable: true, align: "center", editable: true }, { field: 'operate', title: '操作', sortable: true, align: "center", editable: true, formatter:function(value,row,index){ var e = '<a onclick="edit(\''+ row.stationNr + '\')">查看詳情</a> '; return e; } }, ], onCheckAll:function(rows){//全選中 var arr2=new Array(); var arr3=new Array(); arr2=$("#tb_departments").bootstrapTable('getSelections'); for (var i = 0; i < arr2.length; i++) { arr3=arr2[i] for(var s in arr3) arr.push(arr3.stationNr);//添加數(shù)值到數(shù)組\ } var n = []; //一個(gè)新的臨時(shí)數(shù)組 for(var h = 0; h < arr.length; h++) //遍歷當(dāng)前數(shù)組 { //如果當(dāng)前數(shù)組的第i已經(jīng)保存進(jìn)了臨時(shí)數(shù)組,那么跳過(guò), //否則把當(dāng)前項(xiàng)push到臨時(shí)數(shù)組里面 if (n.indexOf(arr[h]) == -1){ n.push(arr[h]); } } arr=n document.getElementById("ddd").value=arr; }, onUncheckAll:function(rows){//全選不中 arr=[];//清空數(shù)組 document.getElementById("ddd").value=arr; }, onUncheck:function(row){//不選中 stationNr2=row.stationNr; //取出id arr.remove(stationNr2); document.getElementById("ddd").value=arr; }, onCheck:function(row){//選中 //alert("2") stationNr2=row.stationNr; //取出id arr.push(stationNr2);//添加數(shù)值到數(shù)組\ //去除重復(fù)元素 var s = arr.join(",")+","; for(var i=0;i<arr.length;i++) { if(s.replace(arr[i]+",","").indexOf(arr[i]+",")>-1) { arr.remove(arr[i]); document.getElementById("ddd").value=arr; break; } } document.getElementById("ddd").value=arr; }, onClickRow:function(row,$element){ $('.success').removeClass('success'); $($element).addClass('success'); stationNr2=row.stationNr; arr.push(stationNr2);//添加數(shù)值到數(shù)組 //定義查詢方法 Array.prototype.indexOf = function(val) { for (var i = 0; i < this.length; i++) { if (this[i] == val) return i; } return -1; }; Array.prototype.remove = function(val) { var index = this.indexOf(val); if (index > -1) { this.splice(index, 1); } }; //去除重復(fù)元素 var s = arr.join(",")+","; for(var i=0;i<arr.length;i++) { if(s.replace(arr[i]+",","").indexOf(arr[i]+",")>-1) { arr.remove(arr[i]); document.getElementById("ddd").value=arr; break; } } document.getElementById("ddd").value=arr; } }); }; //得到查詢的參數(shù) oTableInit.queryParams = function (params) { var temp = { //這里的鍵的名字和控制器的變量名必須一直,這邊改動(dòng),action也需要改成一樣的 limit: params.limit, //頁(yè)面大小 offset: params.offset, //頁(yè)碼 order: params.order, ordername: params.sort,//返回排序列名 //pageSize: params.pageSize, //頁(yè)面大小 //pageNumber: params.pageNumber, //頁(yè)碼 departmentname: $("#departmentname").val(),//返回查詢條件 wells: $("#wells").val(), }; return temp; }; return oTableInit; }; var ButtonInit = function () { var oInit = new Object(); var postdata = {}; oInit.Init = function () { //初始化頁(yè)面上面的按鈕事件 }; return oInit; };
以上所述是小編給大家介紹的bootstrap table分頁(yè)模板和獲取表中的ID,對(duì)Get請(qǐng)求無(wú)效的問(wèn)題,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)億速云網(wǎng)站的支持!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。