一、上下移动
1、在数据库表中新添加一列名为sort,初始值与各条数据的id相同,初始list排序按照sort的值排序。
2、思路是向上移动的时候,查询出当前数据的上一条数据的sort值,两者交换sort值,同理向下移动的时候,查询出下一条数据的sort值,两者交换。
3、ssm框架中的sql及代码实现
1) sql
<select id="infoBySortUp" parameterType="Map" resultType="com.loan.entity.WExcellentCourseEntity">
SELECT * from w_excellent_course c WHERE c.sort < #{sort} ORDER BY c.sort DESC limit 0,1
</select>
<select id="infoBySortDown" parameterType="Map" resultType="com.loan.entity.WExcellentCourseEntity">
SELECT * from w_excellent_course c WHERE c.sort > #{sort} ORDER BY c.sort limit 0,1
</select>
<select id="infoBySort" parameterType="Map" resultType="com.loan.entity.WExcellentCourseEntity">
SELECT * from w_excellent_course where sort=#{sort}
</select>
<update id="updateBySort" parameterType="Map">
UPDATE w_excellent_course SET sort=#{sort} WHERE id=#{id}
</update>
2) service
public WExcellentCourseEntity sortUp(String sort);
public WExcellentCourseEntity sortDown(String sort);
public WExcellentCourseEntity infoBySort(String sort);
public vo