使用框架:springMVC+mybatis,easyuijavascript
廢話不說,直接上代碼,以下:html
html代碼java
<div class='topsearch1 panel-noscroll'> <table id="grid"></table> </div> <div> <form id="selectForm"> <div class="conditions"> <div> <b class="title">監測點等級:</b> <fb:dictionary fcode="145" id="djdm" name="djdm" multiple="false" data-options="editable:false" /> </div> </div> </form> <div align="right"> <a href="javascript:void(0)" class="btnsearch" icon="icon-search" onclick="select()">查詢</a> <a href="javascript:void(0)" class="btnsearch" icon="icon-search" onclick="clear()">重置</a> </div> </div>
js代碼ajax
$(function(){ initDatagrid(djdm); }); function initDatagrid(djdm){ $("#grid").datagrid({ url:"<%=path%>/ycjc/list", queryParams:{ djdm:djdm }, method : 'post', iconCls : 'icon-save', fitColumns : true, fit:true, singleSelect : true, border : false, autoRowHeight : true, striped : true, nowrap : false, rownumbers : true, pagination:true,//分頁控件 toolbar : toolbar, onLoadError : function() { alert('數據加載失敗!'); }, loadMsg : '數據裝載中......', resizeHandle : 'both', columns:[[ {field:'fid',title:'檢測點編號',width:50,hidden:true}, {field:'yjzs',title:'預警總數',width:50,align:"center"}, {field:'jcddj',title:'監測點等級',width:50,align:"center"}, {field:'jcd',title:'監測點',width:100,align:"center"}, {field:'jcgz',title:'監測規則',width:150,align:"center"}, {field:'jcdw',title:'監測單位',width:50,align:"center"}, {field:'jczt',title:'監測狀態',width:50,align:"center"} ]] }); //設置分頁控件 var p = $('#grid').datagrid('getPager'); $(p).pagination({ pageSize: 10,//每頁顯示的記錄條數,默認爲10 pageList: [5,10,15],//能夠設置每頁記錄條數的列表 beforePageText: '第',//頁數文本框前顯示的漢字 afterPageText: '頁 共 {pages} 頁', displayMsg: '當前顯示 {from} - {to} 條記錄 共 {total} 條記錄', onBeforeRefresh: function () { }, onSelectPage: function (page, pageSize) {//分頁觸發 find(page, pageSize); } }); } function find(page, pageSize) { $("#grid").datagrid('getPager').pagination({pageSize : pageSize, page : page});//重置 $("#grid").datagrid("loading"); //加屏蔽 $.ajax({ type : "POST", dataType : "json", url : "<%=path%>/ycjc/list", data : { 'page' : page, 'pageSize' : pageSize }, success : function(data) { $("#grid").datagrid('loadData',pageData(data.rows,data.total));//這裏的pageData是一個對象,用來封裝獲取的總條數,和數據,data.rows是控制器裏面添加的一個map集合的鍵的名稱 $("#grid").datagrid("loaded"); //移除屏蔽 }, error : function(err) { $.messager.alert('操做提示', '獲取信息失敗...請聯繫管理員!', 'error'); $("#grid").datagrid("loaded"); //移除屏蔽 } }); } function pageData(list,total){ var obj=new Object(); obj.total=total; obj.rows=list; return obj; } //查詢 function select(){ djdm=$("#djdm").combobox('getValue'); $('#grid').datagrid({ queryParams:{ djdm:djdm } }); }
java代碼spring
控制器controller: @ResponseBody @RequestMapping("/ycjc/list") public Map<String, Object> getListView(YjxxTjBean yjxx, HttpServletRequest request, Integer page, Integer pageSize) throws Exception { JyjbxxBean jyjbxx = (JyjbxxBean) getObject("CURRENT_POLICE"); Map<String, Object> map = new HashMap<String, Object>(); List<YjxxTjBean> list; try { list = ycjcService.findYjxxList(yjxx, page, pageSize, jyjbxx); int total = ycjcService.findYjxxTotal(yjxx, jyjbxx); //返回的數據list放入rows map.put("rows", list); //total總數 map.put("total", list == null ? 0 : total); } catch (Exception e) { e.printStackTrace(); throw new Exception(e); } return map; } 業務service: @Override public List<YjxxTjBean> findYjxxList(YjxxTjBean yjxx, Integer page, Integer pageSize, JyjbxxBean jyjbxx) { Map<String, Object> conditions = new HashMap<String, Object>(); // 當前頁 page = page == null || page <= 0 ? 1 : page; // 每頁顯示條數 pageSize = pageSize == null || pageSize <= 0 ? 10 : pageSize; int start = (page - 1) * pageSize + 1; int end = start + pageSize - 1; if (yjxx != null) { conditions.put("djdm", yjxx.getDjdm()); } if (jyjbxx != null) { conditions.put("dwdm", jyjbxx.getGajgjgdm()); } conditions.put("start", start); conditions.put("end", end); return ycjcsjBeanMapper.selectYjxxList(conditions); } @Override public int findYjxxTotal(YjxxTjBean yjxx, JyjbxxBean jyjbxx) { Map<String, Object> conditions = new HashMap<String, Object>(); if (yjxx != null) { conditions.put("djdm", yjxx.getDjdm()); } if (jyjbxx != null) { conditions.put("dwdm", jyjbxx.getGajgjgdm()); } return ycjcsjBeanMapper.findYjxxTotal(conditions); }
mapper.xml代碼sql
<sql id="selectPageHeadFragment"> SELECT * FROM( SELECT ROW_.*, ROWNUM ROWNUM_ FROM ( </sql> <sql id="selectPageFootFragment"> ) ROW_ <if test="end != null"> WHERE ROWNUM <= #{end} </if> ) <if test="start != null"> WHERE ROWNUM_ >= #{start} </if> </sql> <select id="selectYjxxList" resultType="com.fable.dwjd.zfbajk.bean.YjxxTjBean" parameterType="java.util.Map"> <include refid="selectPageHeadFragment" /> SELECT T1.FID, COUNT(t2.jcdid) yjzs, (SELECT t.fname FROM COM_DICTIONARY T WHERE T.FCODE = '145' AND t.fvalue = t1.djdm) jcddj, t1.djdm, t1.jcd, t1.jcgz, '省廳' JCDW, (CASE WHEN T1.ISQY = '1' THEN '正常' ELSE '停用' END) JCZT FROM t_zfba_yjxxsj t0, t_zfba_jcd t1, t_zfba_ycjcsj t2 WHERE t2.fid(+) = t0.fid and t2.jcdid = t1.fid and t1.isqy = '1' <if test="dwdm != null and dwdm !=''"> and t1.fpdwlx >= get_yjxxdwdmlevel(#{dwdm,jdbcType=VARCHAR}) and BADWDM like case get_yjxxdwdmlevel(#{dwdm,jdbcType=VARCHAR}) WHEN 3 THEN substr(#{dwdm,jdbcType=VARCHAR},1,6)||'%' WHEN 2 THEN substr(#{dwdm,jdbcType=VARCHAR},1,4)||'%' WHEN 1 THEN substr(#{dwdm,jdbcType=VARCHAR},1,2)||'%' end </if> <if test="djdm != null and djdm!=''"> and t1.djdm=#{djdm,jdbcType=VARCHAR} </if> GROUP BY T1.FID, T1.DJDM, T1.JCD, T1.JCGZ, T1.ISQY <include refid="selectPageFootFragment" /> </select>
此爲工做筆記,若有疑問或不對的地方,歡迎指出,共同窗習共同進步。json