SSM批量删除

jsp页面:

	<input type="checkbox" class="middle children-checkbox" name="check"  value="${info.productId}"/>

<script type="application/javascript">
	function delProduct(){
	   var idArrs = new Array();
	   //var pageNumber=${page.pageNumber}
	   $("input[name=check]:checked").each(function (i) {
	       idArrs[i]=$(this).val();
	   })
	/*for(var i=0;i<$("input[name=check]:checked").length;i++){
	 idArrs[i]=$("input[name=check]:checked").eq(i).val();
	 }*/
	   if(idArrs.length==0){
	       alert("至少要选中一笔资料");
	       return;
	   }
	   if(confirm("确定要删除掉勾选内容吗?")){
	       $.ajax({
	           url : "http://localhost:8080/product/delProduct" ,   // 处理的请求路径
	           type : "POST" ,    // 此处发送的是PUT请求(可变更为其他需要的请求)
	        /*contentType: 'application/json',*/
	           data: {_method:"DELETE",idArrs:idArrs},
	           dataType : "json" , // 返回的数据类型为json类型
	           success : function(data) {
	               //console.log(data);
	               if(data==="success"){
	                   // window.location.href="${pageContext.request.contextPath }/product/pageAll.html?pageNumber="+pageNumber;
	                   //window.location.href=window.location.href
	                   //window.location.reload(true);
	                   //location.replace(location.href);
	                   //window.location=window.location
	                   $("input[name=check]:checked").each(function () {
	                       $(this).parent().parent().parent().remove();
	                   })
	                   $("#msg").text("删除成功!").css("color","green");
	
	               }else{
	                   $("#msg").text("删除失败!").css("color","red");
	               }
	           }
	       });
	   }
	}
  $(function () {
      //全选操作,属性中带有true,false;例如:checked,selected,用prop方法。
      //除以上用prop方法之外,都用attr方法。attr方法在执行一次全选,全不选之后,不会再次执行全选操作。
      $("#all").click(function () {
         if($("input[name=check]:checkbox").is(":checked")){
             $("input[name=check]:checkbox").prop("checked",false);
         }else{
             $("input[name=check]:checkbox").prop("checked",true);
         }

      })

  })
 </script>

controller:

	@RequestMapping(value = "/delProduct",method = RequestMethod.DELETE)
    @ResponseBody
    //此处@RequestParam的idArrs[]要和ajax传过来的参数保持一致,此处加[]代表是数组
    public Object delProduct(@RequestParam(value="idArrs[]") String [] idArrs){
        String jsonString = "";
        productService.delImgs(idArrs);
        int count = productService.delProduct(idArrs);
        System.out.println("count"+count);
        if(count<0) {
            jsonString = JSON.toJSONString(Constants.ERROR_MESSAGE);
            System.out.println(".....");
            return jsonString;
        }else {
            jsonString = JSON.toJSONString(Constants.SUCCESS_MESSAGE);
            return jsonString;
        }
    }

mapper:

	int delProduct(String [] idArrs);
	<delete id="delProduct" parameterType="string" >
        update productinfo set flg=1 where productId in
        <foreach collection="array" item="ids" open="(" separator="," close=")">
            #{ids}
        </foreach>
    </delete>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值