javaWeb上移下移(SpringMVC+Mabits+MySql)

上移:交换本条与上一条的E_SORT(排序的值);
下移:交换本条与下一条的排序值。

移动之前:
移动之前
移动之后:
移动之后
实现代码如下:

/**
 * 修改排序
 * 
 * @param out
 * @author wangsai
 */
@RequestMapping(value = "/upDownMove")  
public void updESort(PrintWriter out){  
    PageData pd=this.getPageData();
    try {
        pd.put("EDIT_TIME", Tools.date2Str(new Date()));
        exampleQuestionService.upDownMove(pd);
        out.print("success");
    } catch (Exception e) {
        e.printStackTrace();
    }
    out.flush();
}
<!-- 上移下移 -->
<update id="upDownMove" parameterType="pd">
    update 
        <include refid="examQuesTableName"></include> 
    set 
        E_SORT = (
            select 
                e.E_SORT 
            from (
                select 
                    E_SORT 
                from 
                    <include refid="examQuesTableName"></include> 
                where 
                    ID = #{ID} 
                and 
                    EXAMPLE_ID = #{EXAMPLE_ID} 
                and 
                    ACTIVE_FALG = '0'
            ) e 
        ),
        EDIT_TIME = #{EDIT_TIME} 
    where 
        ID = (
            select 
                i.ID 
            from (
                select 
                    ID 
                from 
                    <include refid="examQuesTableName"></include> 
                where 
                    E_SORT = #{E_SORT} 
                and 
                    EXAMPLE_ID = #{EXAMPLE_ID} 
                and 
                    ACTIVE_FALG = '0'
            ) i 
        ) 
    and 
        EXAMPLE_ID = #{EXAMPLE_ID} 
    and 
        ACTIVE_FALG = '0';<!-- 正常情况下这句话是没用的 -->

    update 
        <include refid="examQuesTableName"></include> 
    set 
        E_SORT = #{E_SORT},
        EDIT_TIME = #{EDIT_TIME} 
    where 
        ID = #{ID} 
    and 
        ACTIVE_FALG = '0';<!-- 正常情况下这句话是没用的 -->
</update>
<table class="content_main_table">        
    <thead>
        <tr>
            <th style="width:50px;">序号</th>
            <th>问题</th>
            <th style="width: 160px;">移动</th>
            <th style="width: 160px;">操作</th>
        </tr>
    </thead>
    <tbody>
    <!-- 开始循环 -->    
    <c:choose>
        <c:when test="${not empty examQuesList}">
            <c:if test="${QX.cha == 1 }">
                <c:forEach items="${examQuesList}" var="ques" varStatus="i">
                    <tr class="courseList">
                        <td>${i.index+1}<input type='hidden' name='ids' value="${ques.E_SORT}"/></td>
                        <td>
                            <p style="line-height: 30px; color: #000; font-size: 14px;">
                                ${ques.CONTENT}
                            </p>
                        </td>
                        <td>
                            <c:choose>
                            <c:when test="${QX.edit != 1}">
                            无权限
                            </c:when>
                            <c:otherwise>
                            <c:if test="${QX.edit == 1 }">
                            <a class="saveBtn ${i.index+1 == 1 ? 'canNotClick' : ''}" title="上移" onclick="moveUp(this,'${i.index+1}','${ques.ID}')"><i class='icon-arrow-up'></i></a>
                            <a class="whiteBtn ${i.index+1 == fn:length(examQuesList) ? 'canNotClick' : ''}" title="下移" onclick="moveDown(this,'${i.index+1}','${ques.ID}')"><i class='icon-arrow-down'></i></a>
                            </c:if>
                            </c:otherwise>
                            </c:choose>
                        </td>
                        <td>
                            <c:choose>
                                <c:when test="${(QX.edit != 1 && QX.del != 1)}">
                                    无权限
                                </c:when>
                                <c:otherwise>
                                    <c:if test="${QX.edit == 1 }">
                                        <a class="a_blue" title="编辑" onclick="edit('${ques.ID}')"><i class='icon-edit'></i></a>
                                    </c:if>
                                    <c:if test="${QX.del == 1 }">
                                        <a class="delBtn" onclick="del('${ques.ID}');" title="删除"><i class='icon-trash'></i></a>
                                    </c:if>
                                </c:otherwise>
                            </c:choose>
                        </td>
                    </tr>
                </c:forEach>
            </c:if>
            <c:if test="${QX.cha == 0 }">
                <tr>
                    <td colspan="4">您无权查看</td>
                </tr>
            </c:if>
        </c:when>
        <c:otherwise>
            <tr class="main_info">
                <td colspan="4">没有相关数据</td>
            </tr>
        </c:otherwise>
    </c:choose>
    </tbody>
</table>
//上移
function moveUp(obj,index,id) {
    if(index == 1){
        layer.msg("上移到顶了");
        return;
    }
    var self = $(obj);
    var _old = self.closest("tr.courseList");
    var _new = self.closest("tr.courseList").prev("tr");
    if (_new.length > 0) {
        var _temp = _old.html();
        _old.empty().append(_new.html());
        _new.empty().append(_temp);
    }
    // 获取本条信息的上一条信息的eSort
    var eSort = _old.find("input[name='ids']").val();
    $.post("exampleQuestion/upDownMove.do",{E_SORT:eSort,ID:id,EXAMPLE_ID:"${pd.EXAMPLE_ID}"},function(data){
        if(data != 'success'){
            layer.alert("移动失败,请重试!");
        }
        window.location.reload();
    });
}

//下移
function moveDown(obj,index,id) {
    if(index == "${fn:length(examQuesList)}"){
        layer.msg("下移到底了");
        return;
    }
    var self = $(obj);
    var _old = self.closest("tr.courseList");
    var _new = self.closest("tr.courseList").next("tr");
    if (_new.length > 0) {
        var _temp = _old.html();
        _old.empty().append(_new.html());
        _new.empty().append(_temp);
    }
    // 获取本条信息的下一条信息的eSort
    var eSort = _old.find("input[name='ids']").val();
    $.post("exampleQuestion/upDownMove.do",{E_SORT: eSort,ID: id,EXAMPLE_ID: "${pd.EXAMPLE_ID}"},function(data){
        if(data != 'success'){
            layer.alert("移动失败,请重试!");
        }
        window.location.reload();
    });
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值