四.编写TestCoustom.java文件。
package test;
import java.util.ArrayList;
import java.util.Iterator;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.yao.HibernateSessionFactory;
import org.yao.MypdInformation;
public class TestCoustom {
public ArrayList dd(int pagesize,int recordstart){
System.out.println(pagesize);
System.out.println(recordstart);
Session session=HibernateSessionFactory.getSession();
String str="";
ArrayList list=new ArrayList();
try{
Transaction tx=session.beginTransaction();
Query query=session.createQuery("select id,showName,endTime from MypdInformation");
query.setFirstResult(recordstart);
query.setMaxResults(pagesize);
for(Iterator it=query.iterate();it.hasNext();){
//MypdInformation mypd=(MypdInformation) it.next();
Object[] objs=(Object[]) it.next();
System.out.println(objs[0]);
System.out.println(objs[1]);
System.out.println(objs[2]);
MypdInformation beans=new MypdInformation();
beans.setId(Integer.parseInt(objs[0].toString()));
beans.setShowName(objs[1].toString());
beans.setEndTime(objs[2].toString());
list.add(beans);
System.out.println(list.size());
}
tx.commit();
}catch(Exception e){
str=e.toString();
}finally{
session.flush();
session.clear();
HibernateSessionFactory.closeSession();
}
return list;
}
}
五.将数据在前台jsp文件中显示。