上移、下移功能
2016-01-10 20:42
387 查看
实现数据的上移和下移功能
实现效果如下:
功能实现过程为:上移和下移是交换两条数据的位置序号。我将主要业务放在Service,具体操作放在Dao中。
上移的Service层代码:
下移的Service层代码:
下移的Dao层代码:
这些是实现上下移动的主要代码。
实现效果如下:
功能实现过程为:上移和下移是交换两条数据的位置序号。我将主要业务放在Service,具体操作放在Dao中。
上移的Service层代码:
public void moveUp(Long id) { //找出相关的Forum:当前需要移动的板块 Forum forum = getById(id); //当前需要移动的上一个板块 Forum other = forumDao.createLimitQueryUp(forum.getPosition()); //最上面的不能上移 if(other == null){ return; } //交换position的值 int temp = forum.getPosition(); forum.setPosition(other.getPosition()); other.setPosition(temp); //更新到数据库中 forumDao.update(forum); forumDao.update(other); }上移的Dao层代码:
/** * 限定查询:板块向上移动. * @param position * @return */ public Forum createLimitQueryUp(int position) { Forum forum = (Forum) getSession().createQuery("from Forum f where f.position<? order by f.position desc")// .setParameter(0, position).setFirstResult(0).setMaxResults(1).uniqueResult(); return forum; }
下移的Service层代码:
public void moveDown(Long id) { //找出相关的Forum:当前需要移动的板块 Forum forum = getById(id); //当前需要移动的下一个板块 Forum other = forumDao.createLimitQueryDown(forum.getPosition()); //最下面的不能下移 if(other == null){ return; } //交换position的值 int temp = forum.getPosition(); forum.setPosition(other.getPosition()); other.setPosition(temp); //更新到数据库中 forumDao.update(forum); forumDao.update(other); }
下移的Dao层代码:
/** * 限定查询:板块向下移动 * @param position * @return */ public Forum createLimitQueryDown(int position) { Forum forum = (Forum) getSession().createQuery("from Forum f where f.position>? order by f.position asc")// .setParameter(0, position).setFirstResult(0).setMaxResults(1).uniqueResult(); return forum; }
这些是实现上下移动的主要代码。
相关文章推荐
- jQuery学习笔记
- 华为oj 合唱队
- ASP.NET5配置
- Spring Boot 以 jar 包方式运行在后台
- 浅析JavaScript作用域链
- 【图像基础】边缘检测基础
- ButtonGroup & JRadioButton(单选框)
- Web--CSS控制页面(link与import方式差别)
- view事件机制
- Android ListPreference的用法
- 【php】intval()函数
- Android上实现Java和Js交互
- MFC 程序运行过程
- [Reomting Debug] 巧用VS 的remote debug 功能远程调试程序 经验分享.
- BestCoder Round #68 (div.2) 1003.graph (DP+矩阵快速幂)
- 关于swap分区大小
- secureFX中出现中文乱码
- 大话设计模式 第一章 简单工厂模式 C++实现
- mysql表的操作之三范式
- gerrit配置管理