0 0

jquery easy ui 查询问题5

后台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();


js:
    	<script type="text/javascript">
	$(function(){
		  $('#dg').datagrid('getPager').pagination({
			    displayMsg:'当前显示从{from}到{to},共{total}记录',
			    onBeforeRefresh:function(pageNumber, pageSize){
			     $(this).pagination('loading');
			     $(this).pagination('loaded');
			    }
			   });
	});
	
	</script>
 </head>
	<body>

	<table id="dg" title="My Users" class="easyui-datagrid" style="width:700px;height:400px"  
            url="test"  pagination="true" 
            toolbar="#toolbar"  
            rownumbers="true" fitColumns="true" singleSelect="true">  
        <thead>  
            <tr>  
                <th field="id" width="50">id</th>
                <th field="stu_id" width="50">stu_id</th>  
                <th field="stu_name" width="50">stu_name</th>  
                <th field="stu_password" width="50">stu_password</th>  
                <th field="stu_yuanxi" width="50">stu_yuanxi</th>  
                <th field="stu_phone" width="50">stu_phone</th>  
                <th field="stu_qq" width="50">stu_qq</th>  
                <th field="stu_sex" width="50">stu_sex</th> 
                <th field="stu_age" width="50">stu_age</th> 
            </tr>  
        </thead>  
    </table>  
 <div id="toolbar"> 
    <div>
      <span>stu_id:</span>  
	  <input id="stu_id" style="line-height:26px;border:1px solid #ccc">  
	  <span>stu_name:</span>  
	  <input id="stu_name" style="line-height:26px;border:1px solid #ccc">  
	  <a href="#" class="easyui-linkbutton" plain="true" onclick="doSearch()">Search</a>  
  </div> 
  <div> 
	        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">New User</a>  
	        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">Edit User</a>  
	        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">Remove User</a>  
   </div>
 </div>  
      
    <div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"  
            closed="true" buttons="#dlg-buttons">  
        <div class="ftitle">User Information</div>  
        <form id="fm" method="post" novalidate>  

            <div class="fitem">  
                <label>stu_id:</label>  
                <input name="stu_id" class="easyui-validatebox" required="true">  
            </div>  
            <div class="fitem">  
                <label>stu_name:</label>  
                <input name="stu_name" class="easyui-validatebox" required="true">  
            </div>  
            <div class="fitem">  
                <label>stu_password:</label>  
                <input name="stu_password">  
            </div>  
            <div class="fitem">  
                <label>stu_yuanxi:</label>  
                <!-- validType="email" -->
                <input name="stu_yuanxi" class="easyui-validatebox" >  
            </div>  
              <div class="fitem">  
                <label>stu_phone:</label>  
                <input name="stu_phone" class="easyui-validatebox" required="true">  
            </div>  
              <div class="fitem">  
                <label>stu_qq:</label>  
                <input name="stu_qq" class="easyui-validatebox" required="true">  
            </div>  
             <div class="fitem">  
                <label>stu_sex:</label>  
                <input name="stu_sex" class="easyui-validatebox" required="true">  
            </div>  
              <div class="fitem">  
                <label>stu_age:</label>  
                <input name="stu_age" class="easyui-validatebox" required="true">  
            </div>  
              
        </form>  
    </div>  
    <div id="dlg-buttons">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()">Save</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">Cancel</a>  
    </div>  
    <script type="text/javascript">  
        var url;  
        function newUser(){  
            $('#dlg').dialog('open').dialog('setTitle','New User');  
            $('#fm').form('clear');  
            url = 'add';  
        }  
        function editUser(){  
            var row = $('#dg').datagrid('getSelected');  
            if (row){  
                $('#dlg').dialog('open').dialog('setTitle','Edit User');  
                $('#fm').form('load',row);  
                url = 'edit?id='+row.id;  
            }  
        }  
		function saveUser(){
			$('#fm').form('submit',{
				url: url,
				onSubmit: function(){
					return $(this).form('validate');
				},
				success: function(result){
					var result = eval('('+result+')');
					if (result.success){
						$('#dlg').dialog('close');		// close the dialog
						$('#dg').datagrid('reload');	// reload the user data
					} else {
						$.messager.show({
							title: 'Error',
							msg: result.msg
						});
					}
				}
			});
		}
        function destroyUser(){  
        	var row = $('#dg').datagrid('getSelected');
			if (row){
				$.messager.confirm('Confirm','Are you sure you want to remove this user?',function(r){
					if (r){
						$.post('destroy',{id:row.id},function(result){
							if (result.success){
								$('#dg').datagrid('reload');	// reload the user data
							} else {
								$.messager.show({	// show error message
									title: 'Error',
									msg: result.msg
								});
							}
						},'json');
					}
				});
			}
        } 
		function doSearch(){
			$('#dg').datagrid('load',{
				stu_id: $('#stu_id').val(),
				stu_name: $('#stu_name').val(),
			});
		}
    </script> 


前台怎么传值过去,就是说 function doSearch(){
$('#dg').datagrid('load',{
stu_id: $('#stu_id').val(),
stu_name: $('#stu_name').val(),
});
}

这块怎么写url,怎么把值传到后台
2013年3月25日 11:49

3个答案 按时间排序 按投票排序

0 0

采纳的答案

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

2013年3月26日 09:08
0 0

   $('#list').datagrid('options').url = '../../Ashx/News/News_Comment.ashx?func=GetList';
        $('#list').datagrid("reload");

2013年3月25日 18:19
0 0

定义 datagrid 时设置了URL,在调用 load 方法不需要传URL,你最后写的doSearch方法中的调用就是正确的参数传递方法。

2013年3月25日 12:38

相关推荐

Global site tag (gtag.js) - Google Analytics