Java使用displaytag库全选如何获取id,然后批量删除?

<ds:table name="${listNews}" pagesize="3"
            requestURI="${pageContext.request.contextPath}/notice"
            class="table  table-condensed table-striped">
            <ds:column
                title="<input type='checkbox' id='checkall' name='checkall' value='all'">
                <input type="checkbox" id="noticeid" name="noticeid"  />
            </ds:column>
            <ds:column title="编号" property="id"></ds:column>
            <ds:column title="标题" property="title"></ds:column>
            <ds:column title="状态" property="status"></ds:column>
            <ds:column title="发布者" property="publisher"></ds:column>
            <ds:column title="发布时间" property="createtime"></ds:column>
            <ds:column title="修改"
                href="${pageContext.request.contextPath}/notice/toUpdate?id"
                paramId="id" paramProperty="id">
                <span style="color: blue">修改</span>
            </ds:column>
            <ds:column title="查看"
                href="${pageContext.request.contextPath}/notice/details?id"
                paramId="id" paramProperty="id">
                <span style="color: blue">详情</span>
            </ds:column>
        </ds:table>
    </form>
</body>
</html>

请问我如何获取全选之后的id,以数组的格式传递给后端进行批量删除?
后端代码为:

@RequestMapping("/delete")
    public String delete(int[] noticeId) {
        for (int i = 0; i < noticeId.length; i++) {
            boolean result = noticeService.deleteNewsById(noticeId[i]);
            if (result) {
                System.out.println("删除成功");
            } else {
                System.out.println("删除失败");
            }
        }
        return "/jsp/notice/noticelist.jsp";
    }


繁花不似锦
浏览 550回答 2
2回答

慕虎7371278

其实可以用js 写一个方法 点击可以全选,在删除操作中,获取被checked的就可以了function selectAll(obj) {var selected = document.getElementsByName("selected");for(var i = 0; i < selected.length; i++) {selected[i].checked = obj.checked;}}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;全选:<input&nbsp;type="checkbox"&nbsp;onclick="selectAll(this)"&nbsp;/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;选择的id:<input&nbsp;type="checkbox"&nbsp;name="selected"&nbsp;value="${e.id}"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;删除是获得被选择的id: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;sel&nbsp;=&nbsp;document.form.selected; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(&nbsp;var&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;<&nbsp;sel.length;&nbsp;i++)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(sel[i].checked)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ids&nbsp;+=sel[i].value&nbsp;+&nbsp;","; &nbsp;&nbsp;&nbsp;&nbsp;} }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java