赞
踩
- public int deleteCollection(int id) {
- String sql="delete from mycollection where id=? ";
- Object[] params={id};
- int n=0;
- try {
- n=super.executeUpdate(sql,params);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return n;
- }
- public void deleteCollection(String[] id) {
- if(id!=null&&id.length>0) {
- for(String i:id){
- myCollectionDao.deleteCollection(Integer.parseInt(i));
- }
- }
- }
- //点击事件,点击删除按钮
- $(".btn").click(function() {
- if (confirm("是否删除?")) {//防手抖操作
- var flag = false;
- var box1 = $(".else_checkbox");//获取到所有的复选框
- var uids = "";//先暂时定义一个空的变量来存取选中的id
- for (var i = 0; i < box1.length; i++) {
- if (box1[i].checked) {//通过for循环来查找被选中的复选框
- uids += box1[i].value + "_";//将所有选中的复选框的id用下划线连接
- flag = true;
- }
- }
-
- if (flag) {
- $.ajax({
- type: 'post',
- url: "<%=request.getContextPath()%>/qiantai/playServlet?method=deletePiliang",//进入到你的删除servlet路径里去
- data: "uid=" + uids,//将刚刚连接好的uids存放在uid里面
- dataType: "json",
- //成功后开启模态框
- success: function (data) {
- console.log("删除成功!");
- },
- error: function () {
- console.log("错误!");
- }
- });
- }
- });
- request.setCharacterEncoding("utf-8");
- response.setCharacterEncoding("utf-8");
- response.setContentType("text/html;charset=UTF-8");
-
- System.out.println("进入批量删除...");
- if (null != cid) {
- String cid=request.getParameter("uid");//获取到刚刚存放的uid
- String[] cids = new String[]{};
- cids = cid.split("_");//将其_分割,会得到一个数组
- Map map = new HashMap();
- response.setContentType("text/json;charset=utf-8");
- service.deleteCollection(cids);//调用service里的删除方法
- JSONObject object = new JSONObject();
- //使用JSON对象传过去
- object.put("code", "ok");
- object.put("data", cids);
- System.out.println(cids);
- out.write(object.toJSONString(object));
- out.flush();
- out.close();
这样就差不多可以啦!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。