o_haifeng 2013-03-25 11:49
浏览 285
已采纳

jquery easy ui 查询问题

后台java:
[code="java"]
//接受参数page和rows
String page =request.getParameter("page");//每页显示的记录数
String rows = request.getParameter("rows");//当前第几页
String stu_id = request.getParameter("stu_id");
String stu_name = request.getParameter("stu_name");
System.out.println(stu_id);
System.out.println(stu_name);
//当前页

int intPage = Integer.parseInt((page == null || page == "0") ? "1":page);
//每页显示条数

int number = Integer.parseInt((rows == null || rows == "0") ? "10":rows);
//每页的开始记录 第一页为1 第二页为number +1

int start = (intPage-1)*number;

    PrintWriter out = response.getWriter(); 
    StudentDAO sd = new StudentDAOImpl();
    //得到总共有多少条数据
    int totalCount = sd.getCount(stu_id,stu_name);
    ArrayList<Student> students= sd.getStudents(start,number,stu_id,stu_name);

    Map<String, Object> jsonMap = new HashMap<String, Object>();//定义map
    jsonMap.put("total",totalCount);//total键 存放总记录数,必须的  
    jsonMap.put("rows", students);//rows键 存放每页记录 list  
    JSONObject result = JSONObject.fromObject(jsonMap);//格式化result   一定要是JSONObject

    System.out.println(result);

    out.print(result.toString());
    out.flush();
    out.close();

[/code]

js:[code="js"]
<br> $(function(){<br> $(&#39;#dg&#39;).datagrid(&#39;getPager&#39;).pagination({<br> displayMsg:&#39;当前显示从{from}到{to},共{total}记录&#39;,<br> onBeforeRefresh:function(pageNumber, pageSize){<br> $(this).pagination(&#39;loading&#39;);<br> $(this).pagination(&#39;loaded&#39;);<br> }<br> });<br> });</p> <pre><code>&lt;/script&gt; </code></pre> <p></head><br> <body></p> <pre><code>&lt;table id=&quot;dg&quot; title=&quot;My Users&quot; class=&quot;easyui-datagrid&quot; style=&quot;width:700px;height:400px&quot; url=&quot;test&quot; pagination=&quot;true&quot; toolbar=&quot;#toolbar&quot; rownumbers=&quot;true&quot; fitColumns=&quot;true&quot; singleSelect=&quot;true&quot;&gt; &lt;thead&gt; &lt;tr&gt; &lt;th field=&quot;id&quot; width=&quot;50&quot;&gt;id&lt;/th&gt; &lt;th field=&quot;stu_id&quot; width=&quot;50&quot;&gt;stu_id&lt;/th&gt; &lt;th field=&quot;stu_name&quot; width=&quot;50&quot;&gt;stu_name&lt;/th&gt; &lt;th field=&quot;stu_password&quot; width=&quot;50&quot;&gt;stu_password&lt;/th&gt; &lt;th field=&quot;stu_yuanxi&quot; width=&quot;50&quot;&gt;stu_yuanxi&lt;/th&gt; &lt;th field=&quot;stu_phone&quot; width=&quot;50&quot;&gt;stu_phone&lt;/th&gt; &lt;th field=&quot;stu_qq&quot; width=&quot;50&quot;&gt;stu_qq&lt;/th&gt; &lt;th field=&quot;stu_sex&quot; width=&quot;50&quot;&gt;stu_sex&lt;/th&gt; &lt;th field=&quot;stu_age&quot; width=&quot;50&quot;&gt;stu_age&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;/table&gt; </code></pre> <p><div id="toolbar"> <br> <div><br> <span>stu_id:</span><br><br> <input id="stu_id" style="line-height:26px;border:1px solid #ccc"><br><br> <span>stu_name:</span><br><br> <input id="stu_name" style="line-height:26px;border:1px solid #ccc"><br><br> <a href="#" class="easyui-linkbutton" plain="true" onclick="doSearch()">Search</a><br><br> </div> <br> <div> <br> <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">New User</a><br><br> <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">Edit User</a><br><br> <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">Remove User</a><br><br> </div><br> </div> </p> <pre><code>&lt;div id=&quot;dlg&quot; class=&quot;easyui-dialog&quot; style=&quot;width:400px;height:280px;padding:10px 20px&quot; closed=&quot;true&quot; buttons=&quot;#dlg-buttons&quot;&gt; &lt;div class=&quot;ftitle&quot;&gt;User Information&lt;/div&gt; &lt;form id=&quot;fm&quot; method=&quot;post&quot; novalidate&gt; &lt;div class=&quot;fitem&quot;&gt; &lt;label&gt;stu_id:&lt;/label&gt; &lt;input name=&quot;stu_id&quot; class=&quot;easyui-validatebox&quot; required=&quot;true&quot;&gt; &lt;/div&gt; &lt;div class=&quot;fitem&quot;&gt; &lt;label&gt;stu_name:&lt;/label&gt; &lt;input name=&quot;stu_name&quot; class=&quot;easyui-validatebox&quot; required=&quot;true&quot;&gt; &lt;/div&gt; &lt;div class=&quot;fitem&quot;&gt; &lt;label&gt;stu_password:&lt;/label&gt; &lt;input name=&quot;stu_password&quot;&gt; &lt;/div&gt; &lt;div class=&quot;fitem&quot;&gt; &lt;label&gt;stu_yuanxi:&lt;/label&gt; &lt;!-- validType=&quot;email&quot; --&gt; &lt;input name=&quot;stu_yuanxi&quot; class=&quot;easyui-validatebox&quot; &gt; &lt;/div&gt; &lt;div class=&quot;fitem&quot;&gt; &lt;label&gt;stu_phone:&lt;/label&gt; &lt;input name=&quot;stu_phone&quot; class=&quot;easyui-validatebox&quot; required=&quot;true&quot;&gt; &lt;/div&gt; &lt;div class=&quot;fitem&quot;&gt; &lt;label&gt;stu_qq:&lt;/label&gt; &lt;input name=&quot;stu_qq&quot; class=&quot;easyui-validatebox&quot; required=&quot;true&quot;&gt; &lt;/div&gt; &lt;div class=&quot;fitem&quot;&gt; &lt;label&gt;stu_sex:&lt;/label&gt; &lt;input name=&quot;stu_sex&quot; class=&quot;easyui-validatebox&quot; required=&quot;true&quot;&gt; &lt;/div&gt; &lt;div class=&quot;fitem&quot;&gt; &lt;label&gt;stu_age:&lt;/label&gt; &lt;input name=&quot;stu_age&quot; class=&quot;easyui-validatebox&quot; required=&quot;true&quot;&gt; &lt;/div&gt; &lt;/form&gt; &lt;/div&gt; &lt;div id=&quot;dlg-buttons&quot;&gt; &lt;a href=&quot;javascript:void(0)&quot; class=&quot;easyui-linkbutton&quot; iconCls=&quot;icon-ok&quot; onclick=&quot;saveUser()&quot;&gt;Save&lt;/a&gt; &lt;a href=&quot;javascript:void(0)&quot; class=&quot;easyui-linkbutton&quot; iconCls=&quot;icon-cancel&quot; onclick=&quot;javascript:$(&#39;#dlg&#39;).dialog(&#39;close&#39;)&quot;&gt;Cancel&lt;/a&gt; &lt;/div&gt; &lt;script type=&quot;text/javascript&quot;&gt; var url; function newUser(){ $(&#39;#dlg&#39;).dialog(&#39;open&#39;).dialog(&#39;setTitle&#39;,&#39;New User&#39;); $(&#39;#fm&#39;).form(&#39;clear&#39;); url = &#39;add&#39;; } function editUser(){ var row = $(&#39;#dg&#39;).datagrid(&#39;getSelected&#39;); if (row){ $(&#39;#dlg&#39;).dialog(&#39;open&#39;).dialog(&#39;setTitle&#39;,&#39;Edit User&#39;); $(&#39;#fm&#39;).form(&#39;load&#39;,row); url = &#39;edit?id=&#39;+row.id; } } function saveUser(){ $(&#39;#fm&#39;).form(&#39;submit&#39;,{ url: url, onSubmit: function(){ return $(this).form(&#39;validate&#39;); }, success: function(result){ var result = eval(&#39;(&#39;+result+&#39;)&#39;); if (result.success){ $(&#39;#dlg&#39;).dialog(&#39;close&#39;); // close the dialog $(&#39;#dg&#39;).datagrid(&#39;reload&#39;); // reload the user data } else { $.messager.show({ title: &#39;Error&#39;, msg: result.msg }); } } }); } function destroyUser(){ var row = $(&#39;#dg&#39;).datagrid(&#39;getSelected&#39;); if (row){ $.messager.confirm(&#39;Confirm&#39;,&#39;Are you sure you want to remove this user?&#39;,function(r){ if (r){ $.post(&#39;destroy&#39;,{id:row.id},function(result){ if (result.success){ $(&#39;#dg&#39;).datagrid(&#39;reload&#39;); // reload the user data } else { $.messager.show({ // show error message title: &#39;Error&#39;, msg: result.msg }); } },&#39;json&#39;); } }); } } function doSearch(){ $(&#39;#dg&#39;).datagrid(&#39;load&#39;,{ stu_id: $(&#39;#stu_id&#39;).val(), stu_name: $(&#39;#stu_name&#39;).val(), }); } &lt;/script&gt; </code></pre> <p>[/code]</p> <p>前台怎么传值过去,就是说 function doSearch(){<br> $(&#39;#dg&#39;).datagrid(&#39;load&#39;,{<br> stu_id: $(&#39;#stu_id&#39;).val(),<br> stu_name: $(&#39;#stu_name&#39;).val(),<br> });<br> }</p> <p>这块怎么写url,怎么把值传到后台</p>

  • 写回答

3条回答 默认 最新

  • 关注

    你完全可以使用同一个url查询的,只是第一次传过去的参数为0,查询时传过去的参数不为0而已。然后在service层拼接sql调用dao层就可以了,不知道我说的你能否明白

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥15 MATLAB数据处理插值
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的
  • ¥15 硬件IIC从模式的数据发送,中断数据的接收,不能用HAL库(按照时序图)