struts2+spring+hibernate分页代码[比较多]第2/7页

 更新时间:2008年09月27日 15:27:36   作者:  
J2EE系统中分页显示,修改dao层,service层,action层,两个分页类文件,代码如下

package com.last999.im.news.dao.impl;
import java.util.*;
import com.last999.im.news.dao.KindEntityDao;
import com.last999.im.news.entity.KindEntity;
import com.last999.im.news.web.PageTool;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.HibernateException;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class KindEntityDaoHibernate extends HibernateDaoSupport implements KindEntityDao{
public KindEntity get(String uuid){
return (KindEntity)getHibernateTemplate().get(KindEntity.class,uuid);
}
public void save(KindEntity kindEntity){
getHibernateTemplate().save(kindEntity);
}
public void update(KindEntity kindEntity){
getHibernateTemplate().saveOrUpdate(kindEntity);
}
public void delete(KindEntity kindEntity){
getHibernateTemplate().delete(kindEntity);
}
public void delete(String uuid){
getHibernateTemplate().delete((KindEntity)getHibernateTemplate().get(KindEntity.class,uuid));
}
public List findAll(){
return getHibernateTemplate().find("from KindEntity");
}
public KindEntity findKindEntityByName(String name){
List k1 = getHibernateTemplate().find("from KindEntity as ke where ke.name = ?",name);
if (k1 != null && k1.size() == 1){
return (KindEntity)k1.get(0);
}
return null;
}
public int getRows(){
return getHibernateTemplate().find("from KindEntity").size();
}
public List getKindEntity(PageTool pageInfo){
final int size1=pageInfo.getSize();
final int startRow=(pageInfo.getCur()-1)*pageInfo.getSize();
return this.getHibernateTemplate().executeFind(new HibernateCallback(){
public List doInHibernate(Session session) throws HibernateException{
Query query = session.createQuery("from KindEntity");
query.setFirstResult(startRow);
query.setMaxResults(size1);
return query.list();
}
}
);
}
}
SERVICE层接口:
Java代码
复制代码 代码如下:

package com.last999.im.news.service;
import java.util.List;
import com.last999.im.news.web.PageTool;
import com.last999.im.news.entity.KindEntity;
public interface KindEntityManage{
public void addKindEntity(KindEntity entity);
public List findAllKind();
public int getRows();
public List getKindEntity(PageTool pageInfo);
}

复制代码 代码如下:

package com.last999.im.news.service;
import java.util.List;
import com.last999.im.news.web.PageTool;
import com.last999.im.news.entity.KindEntity;
public interface KindEntityManage{
public void addKindEntity(KindEntity entity);
public List findAllKind();
public int getRows();
public List getKindEntity(PageTool pageInfo);
}

相关文章

最新评论