mybatis springmvc批量删除 2最新
service层:
@Override
public void batchDeletes(List list) {
creditDao.batchDeletes(list);
}
控制层controller:
/**
* 批量删除 batch
*/
@RequestMapping(value="/batchDeletes")
@ResponseBody
public List<Credit> batchDeletes(HttpServletRequest request,HttpServletResponse response){
String items = request.getParameter("creditIdbox");
List<String> delList = new ArrayList<String>();
String[] strs = items.split(",");
for (String str : strs) {
delList.add(str);
}
creditService.batchDeletes(delList);
List<Credit> list=creditService.queryUserInfo(null);
ModelAndView mv = new ModelAndView();
Map<String, Object> model = new HashMap<String, Object>();
model.put("creditVOList", list);
mv.addAllObjects(model);
mv.setViewName("queryregister");
return list;
}
mapper.xml:
<!--批量删除 -->
<delete id="batchDeletes" parameterType="java.util.List">
DELETE FROM t_credit where t_credit_id in
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</delete>
页面:
<script type="text/javascript" src="../jquery/jquery-2.1.3.js"></script>
<script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../easyui/locale/easyui-lang-zh_CN.js" ></script>
<script type="text/javascript" src="../easyui/js/index.js"></script>
<link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css" />
<script type="text/javascript" >
$(function(){
$("#button").click(function(){
var form=$("#registerform");
form.prop("action","http://localhost:8080/ssmy2/CreditController/intiqu.do");
form.submit();
});
//方式二:
/*$(function(){
$("#button").click(function(){
document.registerform.action="http://localhost:8080/ssmy/CreditController/intiqu.do";
document.registerform.submit();
});**/
//对查询按钮定死状态
$("#status").val($("#statushidden").val());
});
function selectAll(){
if ($("#SelectAll").is(":checked")) {
$(":checkbox").prop("checked", true);//所有选择框都选中
} else {
$(":checkbox").prop("checked", false);
}
}
$(function(){
$("#deleteuser").click(function(){
//判断至少写了一项
var checkedNum = $("input[name='creditIdbox']:checked").length;
console.log(checkedNum);
if(checkedNum==0){
alert("请至少选择一项!");
return false;
}
if(confirm("确定删除所选项目?")){
var checkedList = new Array();
$("input[name='creditIdbox']:checked").each(function(){
checkedList.push($(this).val());
});
console.log(checkedList[0]);
$.ajax({
type:"POST",
url:"http://localhost:8080/ssmy2/CreditController/batchDeletes.do",
data:{"creditIdbox":checkedList.toString()},
datatype:"json",
success:function(data){
$("[name='creditIdbox']:checkbox").attr("checked",false);
alert('删除成功!');
setTimeout("location.reload()",1000);//页面刷新
},
error:function(data){
alert('删除失败!');
}
});
}
/* var form=$("#registerform");
form.prop("action","http://localhost:8080/ssmy/CreditController/deleteuser.do");
form.submit(); */
});
$("#exports").click(function(){
var form =$("#registerform");
form.prop("action","http://localhost:8080/ssmy2/CreditController/exprotExcel.do");
form.submit();
});
$("#delete").click(function(){
var form =$("#registerform");
form.prop("action","http://localhost:8080/ssmy2/CreditController/batchDeletes.do?creditIdbox=${credit.creditId}");
form.submit();
});
$("#uploadFile").click(function(){
var form =$("#registerform");
form.prop("action","http://localhost:8080/ssmy2/CreditController/uploadFile.do");
form.submit();
});
});
</script>
</head>
<body>
<div id="head">
<form id="registerform" name ="registerform" action="" method="post" enctype="multipart/form-data">
<div class="search-box" style="width:100%;height:40px;">
<label> 登录名: </label>
<input type="text" name="loginName" id="loginName" />
<label style="margin-left:10px;">身份证:</label>
<input type="text" name="IDCard" id="IDCard" />
<label style="margin-left:10px;"> 提交状态:</label>
<select id="status" name="status" style="width:100px;height:20px;">
<option value="">全部</option>
<option value="0">已提交</option>
<option value="1">未提交</option>
</select>
<input type="button" id="button" value="查询" style="width:65px;height:22px;margin-left:20px;"/>
<input type="submit" id="exports" value="导出" style="width:65px;height:22px;margin-left:20px;"/>
</div>
<input type="hidden" name="status" id="statushidden" value="${status }" />
<input type="hidden" name="totalcount" id="totalcount" value="${totalcount }" />
<table border="0" cellpadding="0" cellspacing="0">
<tr style="width:100%; height: 50px;">
<td>
<input type="checkbox" id="SelectAll" name="SelectAll" onclick="selectAll();" style="margin-right:5px;"/>全选</td>
<td>序列</td>
<td >登录名</td>
<td >登录密码</td>
<td >确认密码</td>
<td >身份证号</td>
<td >固定电话</td>
<td >手机号码</td>
<td >邮箱</td>
<td >居住地址</td>
<td id="address">提交状态</td>
<td >创建时间</td>
<td >操作</td>
</tr>
<c:forEach var="credit" items="${creditVOList}" varStatus="status">
<tr style="width: 300px;">
<td><input type="checkbox" name="creditIdbox" id="creditIdbox" value="${credit.creditId }"></td>
<td>${status.index}</td>
<td>${credit.loginName}</td>
<td>${credit.loginPwd}</td>
<td>${credit.againPwd}</td>
<td>${credit.IDCard}</td>
<td>${credit.fixedTelephoneNumber}</td>
<td>${credit.telephoneNumber}</td>
<td>${credit.email}</td>
<td id="address">${credit.address}</td>
<td>${credit.status ==0 ? '已提交':'未提交'}</td>
<td>${creditVO.createtime}</td>
<td>
<!-- <a id="delete" href="http://localhost:8080/ssmy/CreditController/deleteuser.do?creditIdbox=${credit.creditId}">删除</a>-->
<a id="delete" href="http://localhost:8080/ssmy2/CreditController/deleteuser.do?creditIdbox=${credit.creditId}">删除</a>
</td>
</tr>
</c:forEach>
</table>
<c:if test="${empty creditVOList }">
没有任何员工信息.
</c:if> <br/>
<input type="button" value="删除" id ="deleteuser" >
<input type="text" name="username"/>
<input type="file" name="uploadFile"/>
<input type="submit" id="uploadFile" name="开始上传文件" value="开始上传文件"/>
<div id="box" style="border: 1px solid #ccc;"></div
</form>
service层:@Override public void batchDeletes(List list) { creditDao.batchDeletes(list); } 控制层controller/** * 批量删除 batch */ @RequestMapping(value="/batchDeletes") @ResponseBody public List<Credit> batchDeletes(HttpServletRequest request,HttpServletResponse response){ String items = request.getParameter("creditIdbox"); List<String> delList = new ArrayList<String>(); String[] strs = items.split(","); for (String str : strs) { delList.add(str); } creditService.batchDeletes(delList); List<Credit> list=creditService.queryUserInfo(null); ModelAndView mv = new ModelAndView(); Map<String, Object> model = new HashMap<String, Object>(); model.put("creditVOList", list); mv.addAllObjects(model); mv.setViewName("queryregister"); return list; } mapper.xml<!--批量删除 --> <delete id="batchDeletes" parameterType="java.util.List"> DELETE FROM t_credit where t_credit_id in <foreach collection="list" index="index" item="item" open="(" separator="," close=")"> #{item} </foreach> </delete>页面:<script type="text/javascript" src="../jquery/jquery-2.1.3.js"></script><script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script><script type="text/javascript" src="../easyui/locale/easyui-lang-zh_CN.js" ></script><script type="text/javascript" src="../easyui/js/index.js"></script><link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css" /><link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css" /><script type="text/javascript" > $(function(){ $("#button").click(function(){ var form=$("#registerform"); form.prop("action","http://localhost:8080/ssmy2/CreditController/intiqu.do"); form.submit(); }); //方式二: /*$(function(){ $("#button").click(function(){ document.registerform.action="http://localhost:8080/ssmy/CreditController/intiqu.do"; document.registerform.submit(); });**/ //对查询按钮定死状态 $("#status").val($("#statushidden").val()); }); function selectAll(){ if ($("#SelectAll").is(":checked")) { $(":checkbox").prop("checked", true);//所有选择框都选中 } else { $(":checkbox").prop("checked", false); } } $(function(){ $("#deleteuser").click(function(){ //判断至少写了一项 var checkedNum = $("input[name='creditIdbox']:checked").length; console.log(checkedNum); if(checkedNum==0){ alert("请至少选择一项!"); return false; } if(confirm("确定删除所选项目?")){ var checkedList = new Array(); $("input[name='creditIdbox']:checked").each(function(){ checkedList.push($(this).val()); }); console.log(checkedList[0]); $.ajax({ type:"POST", url:"http://localhost:8080/ssmy2/CreditController/batchDeletes.do", data:{"creditIdbox":checkedList.toString()}, datatype:"json", success:function(data){ $("[name='creditIdbox']:checkbox").attr("checked",false); alert('删除成功!'); setTimeout("location.reload()",1000);//页面刷新 }, error:function(data){ alert('删除失败!'); } }); } /* var form=$("#registerform"); form.prop("action","http://localhost:8080/ssmy/CreditController/deleteuser.do"); form.submit(); */ }); $("#exports").click(function(){ var form =$("#registerform"); form.prop("action","http://localhost:8080/ssmy2/CreditController/exprotExcel.do"); form.submit(); }); $("#delete").click(function(){ var form =$("#registerform"); form.prop("action","http://localhost:8080/ssmy2/CreditController/batchDeletes.do?creditIdbox=${credit.creditId}"); form.submit(); }); $("#uploadFile").click(function(){ var form =$("#registerform"); form.prop("action","http://localhost:8080/ssmy2/CreditController/uploadFile.do"); form.submit(); }); }); </script></head><body><div id="head"> <form id="registerform" name ="registerform" action="" method="post" enctype="multipart/form-data"> <div class="search-box" style="width:100%;height:40px;"> <label> 登录名: </label> <input type="text" name="loginName" id="loginName" /> <label style="margin-left:10px;">身份证:</label> <input type="text" name="IDCard" id="IDCard" /> <label style="margin-left:10px;"> 提交状态:</label> <select id="status" name="status" style="width:100px;height:20px;"> <option value="">全部</option> <option value="0">已提交</option> <option value="1">未提交</option> </select> <input type="button" id="button" value="查询" style="width:65px;height:22px;margin-left:20px;"/> <input type="submit" id="exports" value="导出" style="width:65px;height:22px;margin-left:20px;"/> </div> <input type="hidden" name="status" id="statushidden" value="${status }" /> <input type="hidden" name="totalcount" id="totalcount" value="${totalcount }" /> <table border="0" cellpadding="0" cellspacing="0"> <tr style="width:100%; height: 50px;"> <td> <input type="checkbox" id="SelectAll" name="SelectAll" onclick="selectAll();" style="margin-right:5px;"/>全选</td> <td>序列</td> <td >登录名</td> <td >登录密码</td> <td >确认密码</td> <td >身份证号</td> <td >固定电话</td> <td >手机号码</td> <td >邮箱</td> <td >居住地址</td> <td id="address">提交状态</td> <td >创建时间</td> <td >操作</td> </tr> <c:forEach var="credit" items="${creditVOList}" varStatus="status"> <tr style="width: 300px;"> <td><input type="checkbox" name="creditIdbox" id="creditIdbox" value="${credit.creditId }"></td> <td>${status.index}</td> <td>${credit.loginName}</td> <td>${credit.loginPwd}</td> <td>${credit.againPwd}</td> <td>${credit.IDCard}</td> <td>${credit.fixedTelephoneNumber}</td> <td>${credit.telephoneNumber}</td> <td>${credit.email}</td> <td id="address">${credit.address}</td> <td>${credit.status ==0 ? '已提交':'未提交'}</td> <td>${creditVO.createtime}</td> <td> <!-- <a id="delete" href="http://localhost:8080/ssmy/CreditController/deleteuser.do?creditIdbox=${credit.creditId}">删除</a>--> <a id="delete" href="http://localhost:8080/ssmy2/CreditController/deleteuser.do?creditIdbox=${credit.creditId}">删除</a> </td> </tr> </c:forEach> </table> <c:if test="${empty creditVOList }"> 没有任何员工信息. </c:if> <br/> <input type="button" value="删除" id ="deleteuser" > <input type="text" name="username"/> <input type="file" name="uploadFile"/> <input type="submit" id="uploadFile" name="开始上传文件" value="开始上传文件"/> <div id="box" style="border: 1px solid #ccc;"></div> </form>
mybatis springmvc批量删除 2最新的更多相关文章
- Mybatis实现批量删除数据
Mybatis实现批量删除操作 学习内容: 1. 使用 2. 代码实现 2.1 UserMapper.java 接口 2.2 UserMapper.xml 总结: 学习内容: 1. 使用 这里通过动态 ...
- mybatis的批量删除
公司工程用的是Mybatis的example的类,自动生成了对数据库的操作,批量操作的今天用到了,两种方式,一种需要拓展它生成的类,另一种自带的. 批量删除的id是以集合List传递 id以List& ...
- (后端)Mybatis实现批量删除操作(转)
原文地址:https://blog.csdn.net/javaee_sunny/article/details/52511842 一. 这里主要考虑两种参数类型:数组或者集合. 而这点区别主要体现在E ...
- mybatis的批量删除操作
需求描述:将符合某条件的几条记录删除 解决思路:对于多个id,可以使用sql关键词 in ,只要满足数据库的id在你的id集合或者list中,就删除,从而实现批量删除.循环delete方法是在是low ...
- Mybatis实现批量删除
知识点:当传入参数为数组时,XX.xml文件中,标签为collection属性 参考博客:https://blog.csdn.net/javaee_sunny/article/details/5251 ...
- springboot + ajax + mybatis 实现批量删除
实现思路: 1. checkbox全选获取批量删除的id数组 2. ajax以字符串的形式将id数组传给控制器 3. 控制器将字符串分割成List数组作为参数传给mapper 具体代码: 1. 前端代 ...
- mybatis postgresql 批量删除
一.需求介绍 前端是一个列表页面,列表可以进行复选框的选择,后台进行关联表数据的删除. 二.框架介绍 springboot+mybatis 数据库用的postgresql 三.具体代码(前端js) 1 ...
- Mybatis批量删除之Error code 1064, SQL state 42000;
(一)小小的一次记载. (二):最近的项目都是使用MyBatis,批量新增自己都会写了,但是一次批量删除可把我给折腾了下,写法网上都有,但是照着做就是不行,最后问公司的人,问网友才得到答案,那就是jd ...
- 161102、MyBatis中批量插入
方法一: <insert id="insertbatch" parameterType="java.util.List"> <selectKe ...
随机推荐
- 12.Hamming Distance(汉明距离)
Level: Easy 题目描述: The Hamming distance between two integers is the number of positions at which th ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) B 1075B (思维)
B. Taxi drivers and Lyft time limit per test 1 second memory limit per test 256 megabytes input stan ...
- 使用RestTemplate时报错java.lang.IllegalStateException: No instances available for 127.0.0.1
我在RestTemplate的配置类里使用了 @LoadBalanced@Componentpublic class RestTemplateConfig { @Bean @LoadBalanced ...
- IIS Express被局域网访问
在 文件夹 C:\Users\administrator\Documents\IISExpress\config 下面 applicationhost.config 文件里 找到相应的项目 如 < ...
- 如何用css让一个容器水平垂直居中
方法一: 以前设置里面的绿div总是会使用{position:absolute;left:50%;top:50%;margin-left:-div宽度的一半;margin-top:-div高度的一半} ...
- Docker 使用samba 共享文件
Docker 使用samba 共享文件 docker run -it --name samba \ -p 139:139 -p 445:445 \ -v /home/develop/code/de ...
- Go语言基础之12--Channel
一.不同goroutine之间如何进行通讯? 1.全局变量和锁同步 缺点:多个goroutine要通信时,定义太多的全局变量(每个全局变量功能不一样),不好维护 2.Channel 二.channel ...
- Python中的None与 NULL(即空字符)的区别
None是Python的特殊类型,NoneType对象,它只有一个值None. 它不支持任何运算也没有任何内建方法. None和任何其他的数据类型比较永远返回False. None有自己的数据类型No ...
- 解决哈希(HASH)冲突的主要方法
https://blog.csdn.net/xtzmm1215/article/details/47177701 虽然我们不希望发生冲突,但实际上发生冲突的可能性仍是存在的.当关键字值域远大于哈希 ...
- transient关键字与序列化、反序列化
transient,中文翻译是短暂的,和对象序列化.反序列化有关. 一个类只要实现了Serializable接口,则该类实例就可以序列化,具体来说实例的每个非静态成员变量都会序列化.注意是非静态成员变 ...