我用jquery的checkbox实现的删除功能,原生的

controller类

@RequestMapping("/deleteusername.do")
public @ResponseBody
void deleteusername(HttpServletRequest request) {
System.out.println("进入删除方法");
String value = request.getParameter("concentratorids");
System.out.println(value);
String [] arr_id = value.split(",");
for(int i=0;i<arr_id.length;i++){
String id=arr_id[i];

Integer sid= Integer.parseInt(id);
int b=(Integer)userMapper.deleteByPrimaryKey(sid);
System.out.println(b);

}

}

dao接口类

int deleteByPrimaryKey(Integer id);

service类

int deleteUser(Integer id);

impl类

@Override
public int deleteUser(Integer id) {
return userMapper.deleteByPrimaryKey(id);
}

.xml的映射

<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from user
    where id = #{id,jdbcType=INTEGER}
  </delete>

jsp页面

<a href="javascript:;" οnclick="del()" class="btn btn-danger radius" type="button"><i class="icon-trash"></i> 删除</a>

<table id="tmallfeeTable" class="table table-border table-bordered table-hover table-bg table-sort">
    <thead>
      <tr class="text-c">
        <th width="25"><input type="checkbox" name="" value=""></th>
        <th width="80">ID</th>
        <th width="100">用户名</th>
        <th width="40">等级</th>
      </tr>
    </thead>
    <tbody>
     <c:forEach items="${userList}" varStatus="i" var="item" >  
      <tr>
            <td><input type="checkbox" value="${item.id}" name="chk1"></td>
       <td>${item.id}</td> <!-- 拿出javabean的属性 -->
       <td>${item.userName}</td>
       <td>${item.level}</td>
        </tr>  
     </c:forEach>  
    </tbody>
  </table>

//删除
    function del() {
   var id=document.getElementsByName("chk1"); 
   var value = new Array();
   for(var i=0;i<id.length;i++){
        if(id[i].checked){ //.checked
        value.push(id[i].value);  //.push向数组的末尾添加一个或多个元素,并返回新的长度
        alert(id[i].value);
      }
      window.location ='deleteusername.do?concentratorids='+value.toString();
   } 
    } 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值