前端拖曳排序后端代码如何实现呢?就如下面的需求

发送请求时,会往后端发送一个字符串的ids,我们把接收来的ids 用一个数组去接收
public int updateSort(String id){
String []ids = id.split(",");
return columnMapper.updateSort(ids);
}
在Mapper 进行映射
int updateSort(@Param("ids")String[] ids);
最后在xml 文件进行处理
<update id="updateSort">
update mall_column set sort = (
case id
<foreach collection="ids" index="index" item="item">
when #{item} then #{index}
</foreach>
end
)
where id in
<foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
#{item}
</foreach>
</update>
在数据库设计的时候必须要一个字段去进行排序,最终就能达到我们想要的结果了
本文介绍了一种前端拖曳排序功能的后端实现方案,通过解析前端发送的字符串ids,利用MyBatis动态SQL处理,实现数据库记录的排序更新。
2843

被折叠的 条评论
为什么被折叠?



