这是我写的批量删除的一段前端代码
//删除按钮
$(":button[value=删除]").click(function(){
var idlist="";
var idCount=0;
$(":checkbox[checked]").each(function(){
idlist = idlist+$(this).val()+',';
idCount++;
});
if(idCount==0){
alert("请选择删除对象!");
return ;
}
var r=confirm("确认删除"+idCount+"个联系人?");
if (r!=true)
{
idlist="";
return;
}
$(":checkbox[checked]").each(function(){
$("tr[id="+$(this).val()+"]").remove();
});
$.post(
"<c:url value='/Controller/DeleteContacter'/>",
{ids:idlist},
function(data){
var s = "删除数据"+idCount+"条,成功"+data+"条";
alert(s);
window.location.href="<c:url value ='/Controller/FindAll!findAll?page=' />"+"${nowallpage}";
}
);
});
});
这是action部分代码
private String ids;
private ContacterService service;
private InputStream inputStream;
public String execute(){
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");
if(this.ids==null||this.ids.trim().equals("")){
return ERROR;
}
String id[] = this.ids.split("\\,");
List<String> list = new ArrayList<String>();
for(int i= 0;id != null && i < id.length ; i++){
if(id[i].length()==36){
list.add(id[i]);
}
}
//ContacterService service = ContacterServiceImplFactory.getInstance();
int count = this.service.deleteContacter(list);
inputStream = new StringBufferInputStream(count+"");
return SUCCESS;
}
public void setService(ContacterService service) {
this.service = service;
}
public String getIds() {
return ids;
}
public void setIds(String ids) {
this.ids = ids;
}
public InputStream getInputStream() {
return inputStream;
}
这是struts配置片段
<action name="DeleteContacter" class="DeleteContacter">
<result type="stream">
<param name="contentType">text/html</param>
<param name="inputName">inputStream</param>
</result>
<result name="error">
/WEB-INF/jsp/DeleteContacterError.jsp
</result>
</action>
温馨提示:内容为网友见解,仅供参考