
复选框全选全不选反选加批量删除
发布日期:2021-10-12 20:07:57
浏览次数:4
分类:技术文章
本文共 2181 字,大约阅读时间需要 7 分钟。
先看图
一,全选,全不选
1.如何给复选框设置id
这个是第一个复选框即全选全不选反选按钮这是foreach循环中的复选框 这个里面要确定每条数据的id即id="${product.id }",还有class选择器ids,这条数据id对应的value
2.再看js
//全选,全不选
$("#qx").click(function () {
if(this.checked){
$(".ids").each(function () {
$(this).prop("checked", true);
})
}else{
$(".ids").each(function () {
$(this).removeAttr("checked");
})
}
});
//反选
$(".ids").change(function () {
$(".ids:checked").length == $(".ids").length ? $("#qx").prop("checked", true) : $("#qx").prop("checked", false);
})
二, 如何批量删除呢:
//批量删除 function deleteAll(){
根据test name属性得到选中的id,以字符串的形式拼接
obj = document.getElementsByName("test");
ids = [];
for(k in obj){
if(obj[k].checked)
ids.push(obj[k].value);
}
if(ids==""){
layer.alert("请选择要删除的商品!!!");
}else{
layer.confirm('请确认是否删除选中的商品', {
btn: ['删除','取消'] //按钮
}, function()
{
$.post(
"/user/system/deleteAll?ids="+ids,
function(obj){
if(obj=="200"){
layer.alert('删除成功!', function(index){
window.location.href="/user/system/productMangerList?status="+status;
});
}else{
layer.alert("删除失败");
}
},
"text"
);
});
}
}
3.后台如何接收呢
@Controller@RequestMapping(value = "user/system/")public class ProductController {
@Autowired
private IUserService userService;
/*
* 批量删除
*/
@RequestMapping(value = "/deleteAll", method = RequestMethod.POST)
@ResponseBody
public String deleteAll (String ids){
return productService.deleteAll(ids);
}}
4.接口类
public interface IProductService {
String deleteAll(String ids);}
5,业务层
@Servicepublic class ProductServiceImpl implements IProductService{
@Autowired
private IProductMapper productMapper;
@Override
public String deleteAll(String ids) {
try {
//截取“,”通过for循环把数据根据id一个一个删除
String[] productId = ids.split(",");
int p =0;
for (int i = 0; i < productId.length; i++) {
p =productMapper.deleteProduct(productId[i]);
}
if (p>0) {
log.info("商品删除成功!!!!!");
return "200";
}
} catch (Exception e) {
e.printStackTrace();
}
return "500";
}}
6.映射mapper.xml 接口
public interface IProductMapper {
int deleteProduct(String id);}
7.mapper.xml 写sql 这个的删除都是假删除,只是改变一下状态。
update t_sys_product
set status = 3 ,updateTime = NOW() where id = #{id}
Over!!!
转载地址:https://blog.csdn.net/qq_39772439/article/details/90638105 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
表示我来过!
[***.249.79.50]2022年04月14日 03时09分32秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
最新文章
Apache中的Squid代理
2022-02-12
Linux中的防火墙服务iptables
2022-02-12
Unit6.文件目录的权限
2022-02-12
Unit7.文件在系统中的传输
2022-02-12
Linux中的samba服务
2022-02-12
Unit8.系统进程及服务的控制
2022-02-12
Linux中的NFS服务
2022-02-12
Linux中的磁盘共享
2022-02-12
Linux中的防火墙服务firewall
2022-02-12
unit17.ftp服务
2022-02-12
Unit2.文件管理命令
2022-02-12
Unit1.虚拟机管理
2022-02-12
Unit3.输入输出管理
2022-02-12
Unit4.vim的常用功能
2022-02-12
Unit5.用户管理
2022-02-12
Unit9.系统日志管理
2022-02-12
10. linux下的网络配置
2022-02-12
Unit11.虚拟机管理
2022-02-12
Unti12. linux中的软件的管理
2022-02-12
Unit13. kickstart 自动安装脚本的制作
2022-02-12