1. 程式人生 > >多選刪除

多選刪除

1.jsp頁面

<script type="text/javascript">
      function checkBox(name,checked){
    	  $("input[name='"+ name +"']").attr("checked",checked); //全選
      }
      
      function optDelete(name,isDisplay){
    	var s = $("input[name='ids']:checked").size();  //選中的個數
        if(s<=0){
        	alert("請至少選擇一個");
        }
    	if(!confirm("你確定刪除嗎?")){
    		return;
    	}
    	$("#jvForm").attr("action","/brand/deletes.do?name="+name+"&disPlay="+isDisplay);
    	$("#jvForm").attr("method","post").submit(); 
      }
</script>

  

<form id="jvForm">
<table cellspacing="1" cellpadding="0" border="0" width="100%" class="pn-ltable">
	<thead class="pn-lthead">
		<tr>
			<th width="20"><input type="checkbox" onclick="checkBox('ids',this.checked)"/></th>
			<th>品牌ID</th>
			<th>品牌名稱</th>
			<th>品牌圖片</th>
			<th>品牌描述</th>
			<th>排序</th>
			<th>是否可用</th>
			<th>操作選項</th>
		</tr>
	</thead>
	<tbody class="pn-ltbody">
		<c:forEach items="${pagination.list }" var="entry">		
			<tr bgcolor="#ffffff" onmouseout="this.bgColor='#ffffff'" onmouseover="this.bgColor='#eeeeee'">
				<td><input type="checkbox" value="${entry.id }" name="ids"/></td>
				<td align="center">${entry.id }</td>
				<td align="center">${entry.name }</td>
				<td align="center"><img width="40" height="40" src="${entry.allUrl}"/></td>
				<td align="center">${entry.description }</td>
				<td align="center">${entry.sort }</td>
				<td align="center"><c:if test="${entry.isDisplay == 1 }">是</c:if><c:if test="${entry.isDisplay == 0 }">不是</c:if></td>
				<td align="center">
				<a class="pn-opt" href="javascript:void(0)" onclick="window.location.href='/brand/toEdit.do?id=${entry.id}'">修改</a> | <a class="pn-opt"  onclick="if(!confirm('確定要刪除嗎?')) {return false;}  window.location.href='/brand/delete.do?id=${entry.id }&name=${name}&isDisplay=${isDisplay}'" href="javascript:void(0)">刪除</a>
				</td>
			</tr>
		</c:forEach>
	
	</tbody>
</table>
</form>

  2.BrandDao.xml檔案:

<delete id="deleteBrandByKeys" parameterType="Integer">
	    delete from bbs_brand
	    <where>
	      id in
	      <foreach collection="array" item="id" open="(" close=")" separator=",">
	         #{id}
	      </foreach>
	    </where>
</delete>

  3.BrandDao.java:

public interface BrandDao {
     public List<Brand> getBrandListWithPage(Brand brand);
     //刪除選中
     public void deleteBrandByKeys(Integer []ids);
}

3.BrandService與BrandServiceImpl略

4.controller層

	
	@RequestMapping(value="/brand/deletes.do")
	public String deletes(Integer[] ids,String name,Integer isDisplay,ModelMap model){
		//TODO 刪除
				brandService.deleteBrandByKeys(ids);
				if(StringUtils.isNotBlank(name)){
					model.addAttribute("name", name);
				}
				if(null != isDisplay){
					model.addAttribute("isDisplay", isDisplay);
				}
				return "redirect:/brand/list.do";
	}