java的ssm框架简单实现ajax搜索功能


	function searchCompany(){	        		
	       $("#companyTable").hide();//隐藏原来表格内容

			var companyName = $.trim($("#companyName").val());//获取搜索框内容
											
			
			
				$.ajax({
					type : "post",
					dataType : "json",
					
					url : "/admin/searchCompany.do",
					data : {
						companyName : companyName
						
					},
					success : function(data) {
						
						
					
						
							var tableStr = "";
							if (data.length > 0) {
								tableStr = tableStr
										+ ""
										+ ""																														
										+ ""
										+ ""
										+ ""
										+ ""										
							
								for (var i = 0; i < data.length; i++) {																		
									tableStr = tableStr
											+ ""
											+ ""
											+ ""
											+ ""
											+ ""
											+ ""
											+ data[i].userCount
											+ ""
										
											
											
											;


								}
										}
								if (data.length == 0) {
									
									tableStr = tableStr
									+ ""
									+ ""																														
									+ ""
									+ ""
									+ ""
									+ ""
								
									tableStr = tableStr
											+ ""
											+ "";
								}											
								
								 $(".table-responsive").html(tableStr); 
								 tableStr = tableStr
									+ "
机构名称账号注册时间联系方式评测人数
" + data[i].zbxCompany.zbxCompanyname + "" + data[i].zbxAccount + "" + data[i].zbxCreatetime + "" + data[i].zbxPhone + "
机构名称账号注册时间联系方式评测人数
暂无数据...
"; }  });   }

前端部分代码

controller层

@RequestMapping(value = "/admin/searchCompany.do")
	@ResponseBody
	public List searchAdminList(String companyName,HttpServletRequest request, HttpServletResponse response,Model model){
		ZbxAdmin admin=(ZbxAdmin) request.getSession().getAttribute("admin");
		List adminList=null;
		
			
		    adminList=adminService.searchAdminBycompanyName(companyName);	
		  
							 return adminList;
												
	}

service层和dao层根据业务来写。

你可能感兴趣的:(java的ssm框架简单实现ajax搜索功能)