亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

layui+ssm實(shí)現(xiàn)數(shù)據(jù)批量刪除功能

 更新時(shí)間:2023年12月05日 11:48:47   作者:洛洛不覺(jué)  
本篇文章給大家介紹layui+ssm實(shí)現(xiàn)數(shù)據(jù)批量刪除功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

layui+ssm實(shí)現(xiàn)數(shù)據(jù)的批量刪除

在這里插入圖片描述

    //數(shù)據(jù)表格
    table.render({
        id: 'adminList',
        elem: '#adminList',
        url: ctx + "/admin/getAdminList", //數(shù)據(jù)接口
        cellMinWidth: 80,
        even: true,
        toolbar: '#toolbarDemo',//頭部工具欄
        limit: 10,//每頁(yè)條數(shù)
        limits: [10, 20, 30, 40],
        defaultToolbar: ['filter', 'exports', 'print'],
        cols: [[ //表頭
            {type: 'checkbox', fixed: 'left'},
            {type: 'numbers', title: '序號(hào)', width: 80},//序號(hào)列
            // {field: 'id', title: '編號(hào)', align: 'center', width: 80},
            {field: 'username', title: '姓名', align: 'center'},
            {field: 'phone', title: '電話', align: 'center'},
            {
                field: 'gender', title: '性別', align: "center", templet: function (d) {
                    if (d.gender == '2') {
                        return '<button class="layui-btn layui-bg-orange layui-btn-xs ">女</button>';
                    } else if (d.gender == '1') {
                        return '<button class="layui-btn layui-bg-cyan layui-btn-xs layui-btn-normal">男</button>';
                    } else if (d.gender == '') {
                        return '<button class="layui-btn layui-bg-red layui-btn-xs layui-btn-normal">未知</button>';
                    } else {
                        return '';
                    }
                }
            },
            {field: 'roleName', title: '賬戶類型', align: 'center'},
           ],
        page: true,
        loading: true
    });
    /*
    * 監(jiān)聽頭部工具欄
    * */
    table.on('toolbar(adminList)', function (obj) {
        var phone = $("#phone").val(); //獲取前端頁(yè)面?zhèn)鬟^(guò)來(lái)的當(dāng)前登錄人的手機(jī)號(hào)
        var id = obj.config.id;//獲取當(dāng)前操作的id
        var checkStatus = table.checkStatus(id);
        var checkData = checkStatus.data; // 獲取選中的數(shù)據(jù)
        switch (obj.event) {
            case 'deleteBatch':
                if (checkData.length === 0) {
                    layer.msg('請(qǐng)選擇一行數(shù)據(jù)再進(jìn)行操作!');
                } else if (checkData.some(item => item.phone === phone)) {
                    layer.msg("不允許刪除當(dāng)前賬戶!", {icon: 5});
                } else if (checkData.some(item => item.roleName === "超級(jí)管理員")) {
                    layer.msg("此賬戶你沒(méi)有權(quán)限操作!");
                } else {
                    layer.confirm('確定刪除所選賬戶嗎?', function (index) {
                        $.ajax({
                            url: ctx + "/admin/deleteBatch",
                            type: "POST",
                            data: JSON.stringify({ids: checkData}),
                            contentType: "application/json",
                            success: function (d) {
                                if (d.code === 0) {
                                    layer.msg(d.msg, {icon: 1});
                                    table.reload('adminList', {});
                                } else {
                                    layer.msg("失??!", {icon: 5});
                                }
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                layer.msg("獲取數(shù)據(jù)失??! 先檢查sql 及 Tomcat Localhost Log 的輸出");
                            }
                        });
                        layer.close(index);
                    });
                }
                break;
        }
    });

controller

    /*
     * 批量刪除
     * */
    // 定義一個(gè)名為deleteBatch的方法,用于處理批量刪除請(qǐng)求
    @RequestMapping("/deleteBatch")
    @ResponseBody
    public ResultUtil deleteBatch(@RequestBody Map<String, Object> params, HttpSession session) {
        try {
            // 從請(qǐng)求參數(shù)中獲取要?jiǎng)h除的賬戶ID列表
            List<Integer> ids = (List<Integer>) params.get("ids");
            System.out.println(ids);
            // 調(diào)用adminService的deleteByIds方法,根據(jù)ID列表批量刪除賬戶
            adminService.deleteByIds(ids);
            // 返回成功結(jié)果
            return ResultUtil.ok("批量刪除賬戶成功");
        } catch (Exception e) {
            // 如果發(fā)生異常,打印異常堆棧信息
            e.printStackTrace();
            // 返回錯(cuò)誤結(jié)果,狀態(tài)碼為500,提示信息為"sql問(wèn)題"
            return new ResultUtil(500, "sql問(wèn)題");
        }
    }
service
void deleteByIds(List<Integer> ids);
serviceimpl:
   @Override
    public void deleteByIds(List<Integer> ids) {
        adminDao.deleteByIDS(ids);
    }
dao:
 void deleteByIDS( List<Integer> ids);

mapper.xml

  <delete id="deleteByIDS" parameterType="java.util.List">
        DELETE FROM tb_admin
        WHERE id IN
        <foreach collection="list" open="(" close=")" separator="," item="param">
            #{param.id}
        </foreach>
    </delete>

到此這篇關(guān)于layui+ssm實(shí)現(xiàn)數(shù)據(jù)批量刪除的文章就介紹到這了,更多相關(guān)layui ssm批量刪除內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論