获取jsp选中复选框的id传到后台controller

1.前台页面

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<%@include file="/common/jsphead.jsp" %>
<table id="showSbgl" class="table table-border table-bordered table-bg table-hover table-sort">
    <thead>
    <tr class="text-c">
        <th width="3%"><input type="checkbox" name="boxId" onClick="allchecked(this)"/></th>
        <th width="10%">公众号名称</th>
        <th width="10%">保险公司</th>
        <th width="10%">用户ID</th>
        <th width="10%">手机号</th>
        <th width="10%">服务类型</th>
        <th width="5%">支付金额</th>
        <th width="5%">抵扣金额</th>
        <th width="10%">支付时间</th>
        <th width="8%">城市</th>
        <th width="5%">支付状态</th>
        <th width="5%">处理状态</th>
        <th width="5%">结算状态</th>
        <th width="5%">导出状态</th>
        <th width="5%">操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${pagination.results}" var="data">
        <tr class="text-c">
            <td class="text-c" id="chk1"><input class="checkBox" type="checkbox" id="checkIds" name="checkIds" value="${data.id}"/></td>
            <td>${data.sysUsetMsgName}</td>
            <td class="text-c">
                <c:if test="${data.type=='0'}">
                    <span>甄车科技</span>
                </c:if>
                <c:if test="${data.type=='1'}">
                    <span>中煤保险</span>
                </c:if>
                <c:if test="${data.type=='2'}">

                    <span>太平保险</span>
                </c:if>
                <c:if test="${data.type=='3'}">
                    <span>泰山保险</span>
                </c:if>
                <c:if test="${data.type=='4'}">
                    <span>紫金保险</span>
                </c:if>
                <c:if test="${data.type=='5'}">
                    <span>大地保险</span>
                </c:if>
                <c:if test="${data.type=='6'}">
                    <span>阳光保险</span>
                </c:if>

            </td>
            <td>${data.userId}</td>
            <td>${data.tel}</td>
            <td>${data.serviceType}</td>
            <td>${data.payMoney}</td>
            <td>${data.subsidyMoney}</td>
            <td>${data.payTime}</td>
            <td>${data.city}</td>
            <td class="text-c">
                <c:if test="${data.payState=='0'}">
                    <span class="label label-danger radius">未支付</span>
                </c:if>
                <c:if test="${data.payState=='1'}">

                    <span class="label badge-success radius">已支付</span>
                </c:if>
                <c:if test="${data.payState=='2'}">
                    <span class="label label-danger radius">支付失败</span>
                </c:if>
                <c:if test="${data.payState=='3'}">

                    <span class="label badge-success radius">已退款</span>
                </c:if>
            </td>
            <td class="text-c">
                <c:if test="${data.state=='0'}">
                    <span class="label label-danger radius">未处理</span>
                </c:if>
                <c:if test="${data.state=='1'}">

                    <span class="label badge-success radius">处理中</span>
                </c:if>
                <c:if test="${data.state=='2'}">
                    <span class="label badge-success radius">处理完成</span>
                </c:if>
                <c:if test="${data.state=='-1'}">
                    <span class="label label-danger radius">处理失败</span>
                </c:if>
            </td>
            <td class="text-c">
            <c:choose>
            <c:when test="${data.settleAccounts eq '1'}">
                <span class="label badge-success radius">已结算</span>
            </c:when>
            <c:otherwise>
                <span class="label badge-danger radius">未结算</span>
            </c:otherwise>
            </c:choose>
            </td>
            <td class="text-c">
                <c:choose>
                    <c:when test="${data.outState eq '1'}">
                        <span class="label badge-success radius">已导出</span>
                    </c:when>
                    <c:otherwise>
                        <span class="label badge-danger radius">未导出</span>
                    </c:otherwise>
                </c:choose>
            </td>
            <td>

             //这个是单个结算的
                <a style="text-decoration:none" class="ml-5 btn btn-primary-outline radius size-S" onClick="detail2('${data.id}');" title="结算">
                    <i class="Hui-iconfont">&#xe6df;</i>结算
                </a>
                <a style="text-decoration:none" class="ml-5 btn btn-primary-outline radius size-S" onClick="detail('${data.id}');" title="详情">
                    <i class="Hui-iconfont">&#xe6df;</i>详情
                </a>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<tr>
    <td>
        <a style="text-decoration:none" class="ml-5 btn btn-primary-outline radius size-S" onClick="detail3('update','');" title="批量结算">
            <i class="Hui-iconfont">&#xe6df;</i>批量结算
        </a>
    </td>
</tr><br/>
<%@include file="/common/pageInfo.jsp" %>

<script type="text/javascript">

    function detail3(consoleTag, id, stateTag) {
        //table表中选中的复选框赋值给checkedSubject
        var checkedSubject = $('#showSbgl input[name=checkIds]:checkbox:checked');
        var checkedIds="";
        //循环获取选中的复选框的value,这个value是数据表中每条记录的主键${data.id},传给后台,后台就能根据主键查找到数据表的相应记录
        //将其value用逗号隔开拼接成一个字符串
        checkedSubject.each(function() {
            checkedIds=checkedIds+","+$(this).val();
        });

        $.ajax({
            type:"post",
            url:"<%=basePath%>xxx/xxx.htm",
            dataType:"json",
            async:false,
            data:{"checkedIds":checkedIds},
            success:function(data){
                if (data.result){
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg, {icon: 2, time: 1000}, function () {
                        window.location.reload();
                    });
                }

            },
        });

    }
</script>

2.后台控制层

@RequestMapping("insureAgentOrderSettleAccounts")
public void insureAgentOrderSettleAccounts(HttpServletRequest request, HttpServletResponse response) {
    ReturnInfo returnInfo = new ReturnInfo();
    try {
        String[] checkedIds = request.getParameterValues("checkedIds");
        String a="";
        if (checkedIds.length>0&&checkedIds.equals(new String[]{""}) ){
                for (int i = 0; i < checkedIds.length; i++) {
                    String id=checkedIds[i];
                    a +=id+",";
                }
            a = a.substring(1,a.length() - 1);
            String[] str=a.split(",");
            for (int i = 0; i < str.length; i++) {
                String id=str[i];
                InsureRealOrder insureRealOrder=insureRealOrderService.get(id);
                insureRealOrder.setSettleAccounts("1");
                insureRealOrderService.saveOrUpdate(insureRealOrder);
            }
            returnInfo.setResult(true);
            returnInfo.setMsg("结算成功");
        }else {
            returnInfo.setResult(false);
            returnInfo.setMsg("结算失败");
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    writeJson(response, returnInfo);
}
发布了24 篇原创文章 · 获赞 0 · 访问量 741

猜你喜欢

转载自blog.csdn.net/weixin_43355449/article/details/103137217