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();
}
}