表格数据的上移与下移功能
来源:互联网 发布:淘宝上网络解锁可靠吗 编辑:程序博客网 时间:2024/06/11 21:42
【问题】:
在做项目过程中遇到这个需求,根据显示的需要把列表数据进行上移或者下移的操作。
【分析】:
数据库中有position这个字段来管理板块列表显示的顺序,那么当需要上移时,我们需要取到比它position小的,离它最近的一条数据的position值,并把两者进行交换即可。
当数据处于第一条数据时,不能在上移;当数据处于最后一条数据时,不能再下移。
【实现】:
Service:
public void moveDown(Long id) {Forum forum=getById(id);Forum otherForum=(Forum) getSession().createQuery("from Forum f where f.position>? order by f.position desc").setParameter(0, forum.getPosition()).setFirstResult(0).setMaxResults(1).uniqueResult();//最下面的不能下移if(otherForum==null){return;}//交换position的值int temp=forum.getPosition();forum.setPosition(otherForum.getPosition());otherForum.setPosition(temp);//更新到数据库中getSession().update(forum);getSession().update(otherForum);}public void moveUp(Long id) {Forum forum=getById(id);Forum otherForum=(Forum) getSession().createQuery("from Forum f where f.position<? order by f.position asc").setParameter(0, forum.getPosition()).setFirstResult(0).setMaxResults(1).uniqueResult();//最上面的不能上移if(otherForum==null){return;}//交换position的值int temp=forum.getPosition();forum.setPosition(otherForum.getPosition());otherForum.setPosition(temp);//更新到数据库中getSession().update(forum);getSession().update(otherForum);}}Action:
/** * 上移 */public String moveUp() throws Exception{forumManageService.moveUp(model.getId());return "toList";}/** * 下移 */public String moveDown() throws Exception{forumManageService.moveDown(model.getId());return "toList";}页面显示jsp:
<!-- 最上面的不能上移 --><s:if test="#status.first"><span class="disabled">上移</span></s:if><s:else><s:a action="forumManage_moveUp?id=%{id}">上移</s:a></s:else><!-- 最下面的不能下移 --><s:if test="#status.last"><span class="disabled">下移</span></s:if><s:else><s:a action="forumManage_moveDown?id=%{id}">下移</s:a></s:else>【结果显示】:
原来样式:
完成后样式:
0 0
- 表格数据的上移与下移功能
- 节点的上移与下移
- 通用的排序的上移下移功能
- 上移、下移功能
- js上移下移功能
- 按钮实现新闻的上移与下移
- 表格中的上移和下移
- ThinkPHP 实现新闻后台数据上移、下移功能
- jquery 的 $().DataTable() 表格 行数据 上移下移
- flexgrid的上移下移
- JS实现上移下移功能
- VB DataGridView中上移下移功能的实现
- EXT 中tree中节点的上移与下移
- js 脚本实现 上移下移功能
- Flex中List实现上移下移功能
- FLex List 实现上移下移功能
- Flex中List实现上移下移功能
- jquery 实现列表上移、下移功能
- --save-dev 与--save的区别
- POJ 2503 Babelfish
- Android布局优化之Include(一)
- Java之多线程下载工具类
- 第一次编译AOSP简单流程
- 表格数据的上移与下移功能
- 计算机文化基础—IT概论
- DFS搜索排列与组合
- sky patch 简单试用
- 终端,进程组,作业,会话及作业控制
- 系统集成项目管理工程师教程看书笔记6
- maven如何手动将jar包放到本地仓库
- vs2010设置AStyle
- 经典递归(排队买票)