/**
* 先删除图片,再删除记录
* @param ids
*/
//删除告警图片与告警图片在数据库的记录
public void delete(String ids) {
int id[]=StringtoInt(ids);
for(int i=0;i<id.length;i++){
AlertNote note=noteDao.get(id[i]);
File image= new File(path+note.getAlert_pic());
image.delete();
noteDao.delete(id[i]);
}
}
/**
* 字符串ids转为ID 数组
* @param ids
* @return id[]
*/
//
public int[] StringtoInt(String ids) {
String str[] = ids.split(",");
int array[] = new int[str.length];
for(int i=0;i<str.length;i++){
array[i]=Integer.parseInt(str[i]);
}
return array;
}
<s:iterator value="#request.notes">//取出所有对象
<li>
<input type="checkbox" value="${id }" name="checkbox"/>
<div class="note-li">
<p class="noteTitle">${alert_title }</p>
<p class="date">
//格式化时间
<s:date name="alert_time" format="yyyy-MM-dd hh:mm"/></p>
<p class="noteImg" style="display:none">${alert_pic}</p>
</div>
</li>
</s:iterator>
<script type="text/javascript">
$(".checkall").click(function(){
if($(this).text()=="全选"){
$("input[name=checkbox]").each(function(){
$(this).prop("checked",true);
});
$(this).text("取消全选");
}else {
$("input[name=checkbox]").each(function(){
$(this).prop("checked",false);
});
$(this).text("全选");
}
});
//批量删除告警图片记录,以字符串的方式保存选中的ID组
$(".delete").click(function(){
var flag = confirm("确定要删除所选信息吗?");
var input=document.getElementsByName('checkbox');
var ids="";
if(flag){
for(var i=0;i<input.length;i++){
if(input[i].checked){
ids+=input[i].value+",";
}
}
ids=ids.substring(0,ids.length-1);
var url = "note-delete";
var args = {"ids":ids};
$.post(url, args, function(data){
if(data == "1"){
alert("删除成功!");
location.href = "note-list?host_id="+"${param.host_id}";
}else{
alert("删除失败!");
}
});
}
//取消超链接的默认行为
return false;
});
});
</script>