⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 revertinfodao.java

📁 一个oa系统
💻 JAVA
字号:
package com.oa.companyculture.db;

import java.util.List;

import org.hibernate.HibernateException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class RevertInfoDao extends HibernateDaoSupport {

	/**
	 * 根据帖子的id查询回贴信息
	 * 
	 * @param id
	 * @return list
	 */
	public List findByInfoId(int id) {
		 List list = null;
			try {  
				list = (List) this.getHibernateTemplate().find("from Revertinfo where revertid=?", id);
			} catch (HibernateException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return list;
	}

	/**
	 * 添加新的回复信息
	 * 
	 * @param revertinfo
	 */
	public void addRevertInfo(Revertinfo revertinfo) {
		try {  
			this.getHibernateTemplate().save(revertinfo);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 根据帖子的id查询回帖的数目
	 * 
	 * @param id
	 * @return
	 */
	public int findCountByInfoId(int id) {
		 List list = null;
		 int counts = 0;
		 try {  
			list = (List) this.getHibernateTemplate().find("select count(*) from RevertInfo where revertid=?", id);
			String str = list.get(0).toString();
			counts = Integer.parseInt(str);
		 } catch (HibernateException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
		 }
		return counts;
	}

	/**
	 * 根据帖子的id查询此贴的最后回复信息
	 * 
	 * @param id
	 * @return
	 */
	public List findLastByRevertId() {
		List list = null;
		try {  
			list = (List) this.getHibernateTemplate().find("from Revertinfo where id in(select max(id) from Revertinfo group by revertid)");
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
	 }
	   return list;
	}

	/**
	 * 根据回帖的id删除此回复
	 * 
	 * @param id
	 */
	public void deleteRevertInfo(int id) {
		List list = null;
		try {  
			list = (List) this.getHibernateTemplate().find("from Revertinfo where id=?", id);
			Revertinfo revertinfo = (Revertinfo) list.get(0);
			this.getHibernateTemplate().delete(revertinfo);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
	    }
	}

	/**
	 * 根据回帖的id查询帖子的id
	 * 
	 * @param id
	 * @return
	 */
	public int findRevertIdById(int id) {
		List list = null;
		int revertid = 0;
		try {  
			list = (List) this.getHibernateTemplate().find("from Revertinfo where id=?", id);
			Revertinfo revertinfo = (Revertinfo) list.get(0);
		    revertid = revertinfo.getRevertid();
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
	    }
		return revertid;
	}

	/**
	 * 根据帖子的id删除对应的回帖信息
	 * 
	 * @param id
	 */
	public void deleteRevertInfoByRevertId(int id) {
		List list = null;
		try {  
			list = (List) this.getHibernateTemplate().find("from Revertinfo where revertid=?", id);
		for (int i = 0; i < list.size(); i++) {
			Revertinfo revertinfo = (Revertinfo) list.get(i);
			this.getHibernateTemplate().delete(revertinfo);
		}
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
	    }
	}

	/**
	 * 根据回帖的id查询回帖信息
	 * 
	 * @param id
	 * @return
	 */
	public List findById(int id) {
		List list = null;
		try {  
			list = (List) this.getHibernateTemplate().find("from Revertinfo where id=?", id);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
	    }
		return list;
	}

	/**
	 * 修改回帖信息
	 * 
	 * @param revertinfo
	 */
	public void updateRevertInfo(Revertinfo revertinfo) {
		try {
			this.getHibernateTemplate().update(revertinfo);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
	    }
	}
	
	public List findTopRevertId(){
		List list = null;
		try {  
			list = (List)this.getHibernateTemplate().find("from Revertinfo  r1 where r1.id=(select max(r2.id) from Revertinfo r2 where r1.revertid=r2.revertid) order by id desc");
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
	    }			
		return list;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -