Dao层:
public void delmany(String ids) throws Exception {
String hql="";
PreparedStatement pstmt = null;
Connection con = SessionFactoryUtils.getDataSource(getHibernateTemplate().getSessionFactory()).getConnection();
String empIds= ids.substring(0,ids.length()-1);
hql = "delete from Employee where Employee_ID in ("+empIds+")";
pstmt = con.prepareStatement(hql);
pstmt.execute();
pstmt.close();
con.close();
}
对应数据库的表名
页面上全选框:
$("#all").click(function(){
if($(this).attr("checked")==true)
{
$(".check").attr("checked",true);
}
else{
$(".check").attr("checked",false);
}
});
$("#delmany").click(function(){
var ids="";
$(".check").each(function(){
if($(this).attr("checked")){
ids=ids+$(this).val()+",";
}
});
alert(ids);
if(ids==""){
alert("choose data");
return false;
}
if(confirm("sure delete?")){
alert(ids);
$.ajax({
url:"empjson!delmany.action",
type:"POST",
dataType:"json",
data:{"ids":ids},
success:function(){
alert("success");
window.location.href="emp!query.action";
},
error:function(){alert("error");}
});
}
});