码迷,mamicode.com
首页 > 编程语言 > 详细

批量删除实现js+springmvc

时间:2016-09-08 18:21:33      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

前台的控件

<input type=‘checkbox‘ name=‘isSelect‘ value=‘"+data[i].id+"‘ ></input></td>";

绑定按钮:

<input type="button"  onclick="delEdu()" value="Delete" style="color:#95a5a6;  border-radius:5px; vertical-align:middle;height:30px;  width:60px; "/>

js响应函数

function delEdu(){			
				var obj=document.getElementsByName(‘isSelect‘); 
				var s1="Select:"; 
				var ids=‘‘;				
				for(var i=0; i<obj.length; i++){ 
					if(obj[i].checked) ids=ids+obj[i].value+","; //如果选中,将value添加到变量s中 
				} 	
				if(ids==‘‘){
alert("Please choose one!"); } else{ $.get("/portal/edu/delEduList?ids="+ids,function(data){ if("success"==data.result){ // alert("Delete Done!"); window.location.reload(); //load(pn,delFlag); } else{ alert("Error!"); } }); } }

后台controller:

@RequestMapping("/delEduList")
	public void delEduList(Long[] ids,HttpServletResponse response){
		String result = "{\"result\":\"success\"}";
		List<Education> edulistEducations = eduService.getByIds(ids);
		for(Education edu:edulistEducations){
			eduService.delete(edu.getId());
		}
		
		PrintWriter out = null;
	    response.setContentType("application/json");
	    try {
	    	out=response.getWriter();
	        out.write(result);
	    } catch (IOException e) {
	        e.printStackTrace();
	    }
	}	

 

批量删除实现js+springmvc

标签:

原文地址:http://www.cnblogs.com/wujixing/p/5853918.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!