jquery+java選中大量刪除

來源:互聯網
上載者:User

頁面

<#-- 頁頭 --><#assign pageTitle="媒體管理"><#assign currentNav="media"><#include "/wxj/backendCommons/header.ftl"><#-- 引入自訂的宏 --><#include "/macros/macros.ftl"><div id="content-container" class="container">          <div class="col-md-12"><div class="panel panel-default panel-col">  <div class="panel-heading page-header clearfix">        <a  href="/secure/wxj/manage/media/picture" class="btn btn-info btn-sm pull-right" > 返回</a>     <button class="btn btn-info btn-sm pull-right" id="add-picture-btn" data-toggle="modal" data-target="#modal" data-url="/secure/wxj/manage/media/${courseId}/picture/add" data-backdrop="static" style="margin-right:10px;">添加圖片</button>        <a  href="/secure/wxj/manage/media/${courseId}/picture/add?way=batch" class="btn btn-info btn-sm pull-right" style="margin-right:10px;" >大量新增圖片</a>                圖集管理    -- <span>${(course.title)!''}</span>  </div>    <#-- 圖片列表 -->  <div class="panel-body content-picture"><div>          <label class="checkbox-inline"><input id="batch-select" type="checkbox" data-role="batch-select"> 全選</label>          <button id="batch-delete" class="btn btn-default btn-sm mlm" data-role="batch-delete" data-name="圖片" data-url="/secure/wxj/manage/media/picture/delete">刪除</button>        </div>  <a  href="/secure/wxj/manage/media/${courseId}/picture" class="btn btn-info btn-sm pull-right" > 預設排序</a> <a  href="/secure/wxj/manage/media/${courseId}/picture?sort=time" class="btn btn-info btn-sm pull-right" style="margin-right:20px;" > 時間排序</a>     <table class="table table-striped table-hover" id="picture-table">      <thead>        <tr>          <th>序號</th>          <th width="50%">圖片描述</th>          <th>上傳者</th>          <th>顯示順序</th>          <th>添加時間</th>          <th>操作</th>        </tr>      </thead>      <tbody>       <#if uimglist?has_content><#list uimglist as c>        <tr>          <td>          <span> <input value="${(c.imageId)!''}" type="checkbox" data-role="batch-item"></span>            <span>${c_index+1} </span>       </td>          <td>                <a class="pull-left" href="/wxj/picture/${c.courseId}/show" target="_blank">                 <img class="course-picture" src="${c.thumbnailUrl}" width="100" height="56">            </a>                        <a href="#" class="mlm" target="_blank">${(c.description)!''}</a>          </td>                    <td>${c.nickname!"--"}</td>                    <td>          <span>${(c.ordered)!'1'}</span>          </td>          <td>             <span class="text-muted"> ${(c.dateAdded)?string('yyyy-MM-dd HH:mm:ss')}</span>          </td>          <td>                         <div class="btn-group" style="margin-right:10px;">              <button class="btn btn-default btn-sm" data-url="/secure/wxj/manage/media/${(c.imageId)!''}/picture/editor" data-toggle="modal" data-target="#modal" data-backdrop="static">編輯</button>              <a href="#" type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">                <span class="caret"></span>              </a>              <ul class="dropdown-menu pull-right">              <li><a class="delete-picture" data-role="delete-picture" href="javascript:" data-url="/secure/wxj/manage/media/${(c.imageId)!''}/picture/delete"><span class="glyphicon glyphicon-trash"></span> 刪除</a></li>              </ul>            </div>                               <button class="btn btn-info btn-sm" data-url="/secure/wxj/manage/media/${(c.imageId)!''}/picture/replace" data-toggle="modal" data-target="#modal" data-backdrop="static">替換展示圖</button>                         </td>        </tr>  </#list></#if>      </tbody>    </table>  </div></div></div></div></div>    <script>    var app = {};    app.debug = false;    app.controller = 'picture/list';</script><script src="/resources/js/bootstrap-notify.js"></script><script>//批量選中$("#batch-select").click(function(){   if( $(this).is(":checked") == true){        $(".content-picture").find('[data-role=batch-select], [data-role=batch-item]').prop('checked', true);    } else {        $(".content-picture").find('[data-role=batch-select], [data-role=batch-item]').prop('checked', false);    }});//大量刪除$("#batch-delete").click(function(){            var $btn = $(this);                name = $btn.data('name');            var ids = [];            $(".content-picture").find('[data-role=batch-item]:checked').each(function(){                ids.push(this.value);            });            if (ids.length == 0) {                Notify.danger('未選中任何' + name);                return ;            }            if (!confirm('確定要刪除選中的' + ids.length + '張' + name + '嗎。')) {                return ;            }            $(".content-picture").find('.btn').addClass('disabled');            Notify.info('正在刪除' + name + ',請稍等。', 60);            var values=ids.toString();            $.post($btn.data('url'), {ids:values}, function(){                window.location.reload();            });});</script>  <#-- 頁尾開始 --><#include "/wxj/backendCommons/footer.ftl">

控制層:

    /**     * 大量刪除圖片。     */    @RequestMapping(value = "/picture/delete", method = { RequestMethod.GET, RequestMethod.POST })    public ResponseEntity<AjaxPostResponse> deletePictureList(HttpServletRequest request) {        // 待刪除的圖片ID列表        String imageIds = ServletRequestUtils.getStringParameter(request, "ids", "");        String[] imageList = imageIds.toString().split(",");        List<String> imageIdList = Arrays.asList(imageList);// 數群組轉換成list        try {            boolean opStatus = uploadedImageManager.delete(imageIdList);            logger.info("大量刪除圖片:opStatus={}", opStatus);            return this.okResponse(opStatus);        } catch (Exception e) {            logger.error("大量刪除圖片時發生異常, Cause: ", e);            return this.errorResponse(e.getMessage());        }    

serveis:

    @Override    public boolean delete(List<String> imageIds) {        // 刪除通知        UploadedImageExample example = new UploadedImageExample();        example.createCriteria().andImageIdIn(imageIds);        int rows = uploadedImageMapper.deleteByExample(example);        return (rows > 0);    }


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.