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

📄 responsedao.java

📁 bbs论坛 采用java的Web开发strtus、hibernate
💻 JAVA
字号:
package com.wish.bbs.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;

import com.wish.bbs.factory.HibernateSessionFactory;
import com.wish.bbs.pojo.Response;


public class ResponseDAO {
	Session session=null;
	public void getSession(){
		this.session=new Configuration().configure().buildSessionFactory().openSession();
	}
	
	public void save(Response response){
		this.session=HibernateSessionFactory.getSession();
		this.session.save(response);
		this.session.beginTransaction().commit();
		HibernateSessionFactory.closeSession();
	}
	
	public List queryById(String id,int start) {
		this.session=HibernateSessionFactory.getSession();
		String hql = "FROM Response AS r WHERE r.topic.tid=?";
		Query q = this.session.createQuery(hql);
		q.setString(0, id);
		q.setFirstResult(start);
		q.setMaxResults(5);
		List all = q.list();
		HibernateSessionFactory.closeSession();
		return all;
	}
	
	public List queryResponseById(String id) {
		this.session=HibernateSessionFactory.getSession();
		String hql = "FROM Response AS r WHERE r.rid=?";
		Query q = this.session.createQuery(hql);
		q.setString(0, id);
		List all = q.list();
		HibernateSessionFactory.closeSession();
		return all;
	}
	
	public int getCountItems(String tid){
		int count=0;
		this.session=HibernateSessionFactory.getSession();
		String hql="select count(*) from Response as r where r.topic.tid=?";
		Query q=this.session.createQuery(hql);
		q.setString(0, tid);
		List l=q.list();
		if(l.size()>0){
			count=(Integer)l.get(0);
		}
		HibernateSessionFactory.closeSession();
		return count;
	}
}

⌨️ 快捷键说明

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