struts2+spring+hibernate分页代码[比较多]

2016-02-19 11:08 7 1 收藏

下面图老师小编要向大家介绍下struts2+spring+hibernate分页代码[比较多],看起来复杂实则是简单的,掌握好技巧就OK,喜欢就赶紧收藏起来吧!

【 tulaoshi.com - Web开发 】

dao层接口:
Java代码
代码如下:

package com.last999.im.news.dao;
import java.util.*;
import com.last999.im.news.entity.KindEntity;
import com.last999.im.news.web.PageTool;
public interface KindEntityDao{
public KindEntity get(String uuid);
public void save(KindEntity kindEntity);
public void update(KindEntity kindEntity);
public void delete(String uuid);
public void delete(KindEntity kindEntity);
public ListKindEntity findAll();
public KindEntity findKindEntityByName(String name);
public ListKindEntity getKindEntity(PageTool pageInfo);
public int getRows();
}

代码如下:

package com.last999.im.news.dao;
import java.util.*;
import com.last999.im.news.entity.KindEntity;
import com.last999.im.news.web.PageTool;
public interface KindEntityDao{
public KindEntity get(String uuid);
public void save(KindEntity kindEntity);
public void update(KindEntity kindEntity);
public void delete(String uuid);
public void delete(KindEntity kindEntity);
public ListKindEntity findAll();
public KindEntity findKindEntityByName(String name);
public ListKindEntity getKindEntity(PageTool pageInfo);
public int getRows();
}


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);
}


实现类:
Java代码
代码如下:

package com.last999.im.news.service.impl;
import java.util.List;
import com.last999.im.news.web.PageTool;
import com.last999.im.news.entity.KindEntity;
import com.last999.im.news.service.KindEntityManage;
import com.last999.im.news.dao.KindEntityDao;
public class KindEntityManageImpl implements KindEntityManage{
private KindEntityDao kindEntityDao;
public KindEntityDao getKindEntityDao(){
return this.kindEntityDao;
}
public void setKindEntityDao(KindEntityDao kindEntityDao) {
this.kindEntityDao=kindEntityDao;
}
public void addKindEntity(KindEntity kindEntity){
this.getKindEntityDao().save(kindEntity);
}
public List findAllKind(){
return this.getKindEntityDao().findAll();
}
public int getRows(){
return this.getKindEntityDao().getRows();
}
public List getKindEntity(PageTool pageInfo){
return this.getKindEntityDao().getKindEntity(pageInfo);
}
}

代码如下:

package com.last999.im.news.service.impl;
import java.util.List;
import com.last999.im.news.web.PageTool;
import com.last999.im.news.entity.KindEntity;
import com.last999.im.news.service.KindEntityManage;
import com.last999.im.news.dao.KindEntityDao;
public class KindEntityManageImpl implements KindEntityManage{
private KindEntityDao kindEntityDao;
public KindEntityDao getKindEntityDao(){
return this.kindEntityDao;
}
public void setKindEntityDao(KindEntityDao kindEntityDao) {
this.kindEntityDao=kindEntityDao;
}
public void addKindEntity(KindEntity kindEntity){
this.getKindEntityDao().save(kindEntity);
}
public List findAllKind(){
return this.getKindEntityDao().findAll();
}
public int getRows(){
return this.getKindEntityDao().getRows();
}
public List getKindEntity(PageTool pageInfo){
return this.getKindEntityDao().getKindEntity(pageInfo);
}
}


action类:
Java代码
代码如下:

package com.last999.im.news.action;
import java.util.List;
import com.last999.im.news.web.PageTool;
import com.last999.im.news.web.PageMaker;
import com.last999.im.news.entity.KindEntity;
import com.last999.im.news.service.KindEntityManage;
public class KindViewAction extends SafeStruts2{
private List kindList;
private KindEntity kindEntity;
private KindEntityManage kindEntityManage;
private int ppp;
private PageMaker pageMaker;
private String pager;
public String getPager(){
return this.pager;
}
public void setPager(String pager) {
this.pager=pager;
}
public PageMaker getPageMaker(){
return this.pageMaker;
}
public void setPageMaker(PageMaker pageMaker) {
this.pageMaker=pageMaker;
}
public int getPpp(){
return this.ppp;
}
public void setPpp(int ppp) {
this.ppp=ppp;
}
public KindEntityManage getKindEntityManage(){
return this.kindEntityManage;
}
public void setKindEntityManage(KindEntityManage kindEntityManage) {
this.kindEntityManage=kindEntityManage;
}
public KindEntity getKindEntity(){
return this.kindEntity;
}
public void setKindEntity(KindEntity kindEntity) {
this.kindEntity=kindEntity;
}
public List getKindList(){
return this.kindList;
}
public void setKindList(List kindList) {
this.kindList=kindList;
}
public String kindView(){
PageTool pageInfo = new PageTool();
pageInfo.setCur(this.getPpp());
pageInfo.setTotal(this.getKindEntityManage().getRows());
setKindList(this.getKindEntityManage().getKindEntity(pageInfo));
PageMaker pageMaker = new PageMaker();
setPager(pageMaker.makeList(pageInfo,"kindView.action?ppp="));
return SUCCESS;
}
}

代码如下:

package com.last999.im.news.action;
import java.util.List;
import com.last999.im.news.web.PageTool;
import com.last999.im.news.web.PageMaker;
import com.last999.im.news.entity.KindEntity;
import com.last999.im.news.service.KindEntityManage;
public class KindViewAction extends SafeStruts2{
private List kindList;
private KindEntity kindEntity;
private KindEntityManage kindEntityManage;
private int ppp;
private PageMaker pageMaker;
private String pager;
public String getPager(){
return this.pager;
}
public void setPager(String pager) {
this.pager=pager;
}
public PageMaker getPageMaker(){
return this.pageMaker;
}
public void setPageMaker(PageMaker pageMaker) {
this.pageMaker=pageMaker;
}
public int getPpp(){
return this.ppp;
}
public void setPpp(int ppp) {
this.ppp=ppp;
}
public KindEntityManage getKindEntityManage(){
return this.kindEntityManage;
}
public void setKindEntityManage(KindEntityManage kindEntityManage) {
this.kindEntityManage=kindEntityManage;
}
public KindEntity getKindEntity(){
return this.kindEntity;
}
public void setKindEntity(KindEntity kindEntity) {
this.kindEntity=kindEntity;
}
public List getKindList(){
return this.kindList;
}
public void setKindList(List kindList) {
this.kindList=kindList;
}
public String kindView(){
PageTool pageInfo = new PageTool();
pageInfo.setCur(this.getPpp());
pageInfo.setTotal(this.getKindEntityManage().getRows());
setKindList(this.getKindEntityManage().getKindEntity(pageInfo));
PageMaker pageMaker = new PageMaker();
setPager(pageMaker.makeList(pageInfo,"kindView.action?ppp="));
return SUCCESS;
}
}


分页辅助工具类:
Java代码
package com.last999.im.news.web;

public class PageTool{

private int cur=1;
private int size=6;
private int total=1;

public int getCur(){
return this.cur;
}
public void setCur(int cur) {
this.cur=cur;
}
public int getSize(){
return this.size;
}
public void setSize(int size) {
this.size=size;
}
public int getTotal(){
return this.total;
}
public void setTotal(int total) {
this.total=total;
}

public PageTool(){}

public PageTool(int cur,int size,int total){
this.cur=cur;
this.size=size;
this.total=total;
}

public PageTool(int size){
this.size=size;
this.cur=1;
this.total=1;
}
}

package com.last999.im.news.web;

public class PageTool{

private int cur=1;
private int size=6;
private int total=1;

public int getCur(){
return this.cur;
}
public void setCur(int cur) {
this.cur=cur;
}
public int getSize(){
return this.size;
}
public void setSize(int size) {
this.size=size;
}
public int getTotal(){
return this.total;
}
public void setTotal(int total) {
this.total=total;
}

public PageTool(){}

public PageTool(int cur,int size,int total){
this.cur=cur;
this.size=size;
this.total=total;
}

public PageTool(int size){
this.size=size;
this.cur=1;
this.total=1;
}
}

package com.last999.im.news.web;

public class PageTool{

private int cur=1;
private int size=6;
private int total=1;

public int getCur(){
return this.cur;
}
public void setCur(int cur) {
this.cur=cur;
}
public int getSize(){
return this.size;
}
public void setSize(int size) {
this.size=size;
}
public int getTotal(){
return this.total;
}
public void setTotal(int total) {
this.total=total;
}

public PageTool(){}

public PageTool(int cur,int size,int total){
this.cur=cur;
this.size=size;
this.total=total;
}

public PageTool(int size){
this.size=size;
this.cur=1;
this.total=1;
}
}

来源:http://www.tulaoshi.com/n/20160219/1596625.html

延伸阅读
标签: Web开发
分页代码:%''本程序文件名为:Pages.asp%%''包含ADO常量表文件adovbs.inc,可从"\Program Files\Common Files\System\ADO"目录下拷贝%!--#Include File="adovbs.inc"--%''*建立数据库连接,这里是Oracle8.05数据库 Set conn=Server.CreateObject("ADODB.Connection") conn.Open "Provider=msdaora.1;Data Source=YourSrcName;User ID=YourUs...
多数IT 组织都必须解决三个主要问题:1.帮助组织减少成本 2.增加并且保持客户 3.加快业务效率。完成这些问题一般都需要实现对多个业务系统的数据和业务逻辑的无缝访问,也就是说,要实施系统集成工程,以便联结业务流程、实现数据的访问与共享。 JpetStore 4.0是ibatis的最新示例程序,基于Struts MVC框架(注:非传统Struts开发模式...
标签: Java JAVA基础
安装篇 一,下载安装 j2sdk1.4(www.sun.com))或以上,设置 CLASSPATH,java_home。 二,下载服务器,免费版本的有 tomcat,resin,当然也还有 weblogic之类的巨无霸,不过得看你电脑的配置是否承受的了! 这里只以resin来说明,其他的配置都差不多,可以查看各个服务器自带的说明文件。 resin 服务器可...
这篇文章的目的不是为了提供所使用的工具或技术的具体信息,而是提供给用 MDA 技术的体验。请参阅 下载一节 获得示例应用程序的完整源代码。请参阅 参考资料 下载 AndroMDA 和 JBoss,它们是运行示例所需要的软件。 开始 AndroMDA 使用 XML 元数据交换(XML Metadata Interchange,XMI)文件格式的输出,几乎所有的建模工具...
标签: Java JAVA基础
Hibernate 可以实现分页查询,例如: 从第2万条开始取出100条记录 Query q = session.createQuery("from Cat as c"); q.setFirstResult(20000); q.setMaxResults(100); List l = q.list(); 那么Hibernate底层如何实现分页的呢?实际上Hibernate的查询定义在net.sf.hibernate.loader.Loader这个...

经验教程

378

收藏

41
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部