?? responsedao.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 + -