zoukankan      html  css  js  c++  java
  • mybatis 注解 批量更新

    一、前端代码

    toShare:function() {
            //判断选中状态
            var ids ="";
            //判断选中状态
            var num = 0;
            $(".checkbox").each(function () {
                if($(this).is(':checked')){
                    ids +=$(this).val() + ",";
                    num++;
                }
            });
            if(num <= 0){
                toastr.error('请选择要共享的文件!');
                return false;
            }
            ids = ids.slice(0,ids.length-1);
            //共享
            $.ajax({
                cache: false,
                type: "post",
                url:backbasePath+'/apia/v1/file/shareFile',
                dataType:'json',
                data:{
                    token:$("#token").val(),
                    id:ids,
                },
                async: true,
                success: function(data) {
                    if('000000'==data.code){
                        toastr.success(data.msg);
                        // 上传成功之后进行table的重新加载
                        $('#filesList').DataTable().ajax.reload();
                        // 设置不选中状态
                        $("#checkBoxMaster").prop("checked",false);
                    } else if ('900000' == data.code) {
                        toastr.error('共享失败!');
                    } else {
                        toastr.error(data.msg);
                    }
                },
                error: function () {
                    toastr.error('共享失败!');
                }
            });
        }

    二、后端代码

    1、业务逻辑层

       // 共享文件
        @Transactional
        public String shareFile(HttpServletRequest req){
            String result="";
            try{
                Map<String, Object> m = getMaps(req);
                log.info("|" + m + "|");
                // 获取选中的id
                String ids=m.get("id").toString();
                //将获取到的选中的列表封装在list中
                List<String> list = new ArrayList<String>();
                String[] stIds = ids.split(",");
                for (String value : stIds){
                    list.add(value);
                }
                int number =knowledgeDao.updateById(list);
                if(number > 0){
                    result= RequestResponseTool.getJsonMessage(RespCode.commonSucc, RespMsg.commonSucc);
                }
             }catch(Exception e){
                rollBack(e,log);
                result= RequestResponseTool.getJsonMessage(RespCode.commonFail, RespMsg.commonFail);
            }
            return result;
        }

    2、持久层

        /**
         * 共享文件
         * * @return
         */
        @Update("<script>" +
                " update dzj_knowledge_resource_info set is_public='1' where id in " +
                " <foreach collection='ids' item='id' index='index' open='('  separator=',' close=')' >" +
                " #{id}" +
                " </foreach>" +
                "</script>")
        int updateById(@Param("ids")List<String> ids);
  • 相关阅读:
    开网页自动进入路由器设置界面的解决办法(腾达路由器)
    SQL基本语句
    驱动调试配置
    【转】snort
    【转】snort.conf分析(中文)
    【转】snort 笔记2 ----- 规则编写
    【转】Snort语法规则说明及实例讲解
    【转】Snort 命令参数详解
    POST教程笔记
    POST教程笔记
  • 原文地址:https://www.cnblogs.com/flyShare/p/12518378.html
Copyright © 2011-2022 走看看