📄 srehwdao.java
字号:
package cn.hope.front.pojo.dao;
import java.util.List;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import org.apache.log4j.Logger;
import cn.hope.front.pojo.base.BaseSRehwDAO;
public class SRehwDAO extends BaseSRehwDAO {
/**
* Default constructor. Can be used in place of getInstance()
*/
public SRehwDAO () {}
Logger log = Logger.getLogger(TTestInfoDAO.class.getName());
private int count = 0;
public int getCount() {
return this.count;
}
public List searchSRhw(String id, int start, int range, boolean isEq)throws HibernateException{
StringBuffer sqlStr = new StringBuffer();
StringBuffer condition = new StringBuffer();
StringBuffer sqlCnt = new StringBuffer();// 取总记录数
sqlCnt.append("select count(sRehw.srhId) from SRehw sRehw where sRehw.flag='0' and sRehw.student.SUsername='"+id+"'");//计算结果总和
sqlStr.append("select sRehw from SRehw sRehw where sRehw.flag='0' and sRehw.student.SUsername='"+id+"'");
System.out.println(sqlStr+"!!!!!!!!!!!!!!!!");
List list = null;
try {
initialize();
Query queryCnt = this.getSession().createQuery(
sqlCnt.toString() + condition);// 通过hibernate的Query方法查询数据库(自己看文档)
Integer count = (Integer) queryCnt.uniqueResult();// 得到总记录数
this.count = count.intValue();
Query query = this.getSession().createQuery(sqlStr.toString());
query.setFirstResult(start);// 设置查询起始记录数
query.setMaxResults(range);// 设置查询总记录数
list = query.list();
}
catch(HibernateException e){
log.error(e);
e.printStackTrace();
throw new HibernateException(e);
}
finally{
closeCurrentThreadSessions();
}
return list;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -