目录

前端表格拖动排序-后端sql

前端表格拖动排序 后端sql

https://i-blog.csdnimg.cn/blog_migrate/728047fd1386f46b9da0ab41b199b845.png

如果把10条数据拖动到第2条的位置 [2,9]条数据的step+1 把step=10更改成step=2

如果把2条数据拖动到第10条的位置 [2,9]条数据的step-1 把step=2更改成step=10

dao

//把beginIndex条数据拖动到第endIndex条数据上
//如果beginIndex>endIndex param=1 else param=-1
void sort (Integer beginIndex, Integer endIndex, Integer param);

mapper

 <update id="sort" parameterType="java.lang.Integer">
        UPDATE
         testcase t1,
         testcase t2
        SET t1.step = t1.step + #{param3},
         t2.step = #{param2}
        WHERE
        t2.step = #{param1}
        <choose>
            <when test="param1 > param2">
                AND t1.step BETWEEN #{param2}
                AND #{param1}-1
            </when>
            <otherwise>
                AND t1.step BETWEEN #{param1}
                AND #{param2}
            </otherwise>
        </choose>

    </update>