五、 业务逻辑层
在业务逻辑层需要认真思考每个业务逻辑所能用到的持久层对象和DAO。DAO层之上是业务逻辑层,DAO类可以有很多个,但业务逻辑类应该只有一个,可以在业务逻辑类中调用各个DAO类进行操作。
1、创建服务接口类IBookService
1、创建服务接口类IBookService
packagecom.sterning.books.services.iface;

importjava.util.List;

importcom.sterning.books.model.Books;


publicinterfaceIBooksService
{
ListgetAll();//获得所有记录
ListgetBooks(intpageSize,intstartRow);//获得所有记录
intgetRows();//获得总行数
intgetRows(Stringfieldname,Stringvalue);//获得总行数
ListqueryBooks(Stringfieldname,Stringvalue);//根据条件查询
ListgetBooks(Stringfieldname,Stringvalue,intpageSize,intstartRow);//根据条件查询
BooksgetBook(StringbookId);//根据ID获得记录
StringgetMaxID();//获得最大ID值
voidaddBook(Bookspd);//添加记录
voidupdateBook(Bookspd);//修改记录
voiddeleteBook(StringbookId);//删除记录
}
com.sterning.books.services.iface.IBookService.java
2、实现此接口类:BookService:
packagecom.sterning.books.services;

importjava.util.List;

importcom.sterning.books.dao.iface.BooksDao;
importcom.sterning.books.model.Books;
importcom.sterning.books.services.iface.IBooksService;


publicclassBooksServiceimplementsIBooksService
{
privateBooksDaobooksDao;


publicBooksService()
{}


/***//**
*函数说明:添加信息
*参数说明:对象
*返回值:
*/

publicvoidaddBook(Booksbook)
{
booksDao.addBook(book);
}


/***//**
*函数说明:删除信息
*参数说明:对象
*返回值:
*/

publicvoiddeleteBook(StringbookId)
{
Booksbook=booksDao.getBook(bookId);
booksDao.deleteBook(book);
}


/***//**
*函数说明:获得所有的信息
*参数说明:
*返回值:信息的集合
*/

publicListgetAll()
{
returnbooksDao.getAll();
}


/***//**
*函数说明:获得总行数
*参数说明:
*返回值:总行数
*/

publicintgetRows()
{
returnbooksDao.getRows();
}


/***//**
*函数说明:获得所有的信息
*参数说明:
*返回值:信息的集合
*/

publicListgetBooks(intpageSize,intstartRow)
{
returnbooksDao.getBooks(pageSize,startRow);
}


/***//**
*函数说明:获得一条的信息
*参数说明:ID
*返回值:对象
*/

publicBooksgetBook(StringbookId)
{
returnbooksDao.getBook(bookId);
}


/***//**
*函数说明:获得最大ID
*参数说明:
*返回值:最大ID
*/

publicStringgetMaxID()
{
returnbooksDao.getMaxID();
}


/***//**
*函数说明:修改信息
*参数说明:对象
*返回值:
*/

publicvoidupdateBook(Booksbook)
{
booksDao.updateBook(book);
}


/***//**
*函数说明:查询信息
*参数说明:集合
*返回值:
*/

publicListqueryBooks(Stringfieldname,Stringvalue)
{
returnbooksDao.queryBooks(fieldname,value);
}


/***//**
*函数说明:获得总行数
*参数说明:
*返回值:总行数
*/

publicintgetRows(Stringfieldname,Stringvalue)
{
returnbooksDao.getRows(fieldname,value);
}


/***//**
*函数说明:查询信息
*参数说明:集合
*返回值:
*/

publicListgetBooks(Stringfieldname,Stringvalue,intpageSize,intstartRow)
{
returnbooksDao.getBooks(fieldname,value,pageSize,startRow);
}


publicBooksDaogetBooksDao()
{
returnbooksDao;
}


publicvoidsetBooksDao(BooksDaobooksDao)
{
this.booksDao=booksDao;
}

}
com.sterning.books.services.BookService.java
未完待续 。。。。。。
分享到:
相关推荐
Struts2+Spring+Hibernate和Struts2+Spring+Ibatis是两种常见的Java Web应用程序集成框架,它们分别基于ORM框架Hibernate和轻量级数据访问框架Ibatis。这两种框架结合Spring,旨在提供一个强大的、可扩展的、易于...
Struts2+Spring2+Hibernate3 web应用示例
这个“博客Struts2+Spring2+Hibernate3 web应用示例”旨在展示如何将这三个框架有效地结合在一起,以实现一个完整的后端管理系统,比如书管理应用。 Struts2是Action导向的MVC框架,负责处理HTTP请求,提供控制器层...
Struts2、Spring3和Hibernate4是Java Web开发中的三个核心框架,它们分别负责MVC(Model-View-Controller)架构中的控制层、业务层和服务层。本示例结合这三个框架,提供了一种完整的三层架构实现,以提高开发效率和...
《轻量级Java EE企业应用实战(第4版)》这本书深入探讨了Struts 2、Spring 4和Hibernate这三大框架的整合开发,旨在帮助读者掌握如何在实际项目中高效构建Java EE应用。SSH(Struts 2、Spring、Hibernate)是Java ...
《轻量级Java EE企业应用实战:Struts2+Spring3+Hibernate整合开发(第3版)》介绍了Java EE领域的三个开源框架:Struts 2、Spring和Hibernate。其中Struts 2升级到2.2.1,Spring升级到3.0.5,Hibernate升级到了...
这个“Struts2+Hibernate+Spring基于单表的增删改查code”项目是一个典型的Java Web应用程序示例,用于教学初学者如何在实际开发中运用这三个框架来实现对数据库中单个表的操作。 **Struts2** 是一个MVC(Model-...
本文将详细介绍如何实现Struts2、Spring3和Hibernate三个框架的整合。这种整合通常被称为SSH(Struts2-Spring-Hibernate)框架集成,是Java Web开发中非常流行的一种组合方式。通过这三个框架的联合使用,可以构建出...
Struts2、Spring和Hibernate是Java Web开发中的三大框架,它们的整合应用极大地提升了开发效率和项目的可维护性。在本示例中,我们将探讨如何将这三个框架集成在一起,实现一个完整的MVC(模型-视图-控制器)架构。 ...
应广大网友需求,自己抽了点时间写了一个Struts2.0+Spring2.0+Hibernate3.1的登录及增删改查的完整演示示例,以此奉献给大家,由于本人水平有限,有写的不好的地方还望大家多提宝贵意见,如果有不明白的地方请关注我的...
Struts2.3 + Spring3.2 + Hibernate4.1 + HTML5 + CSS3开发示例代码。 其中包括如下文件: 介绍文档 Struts2.3 + Spring3.2 + Hibernate4.1 + HTML5 + CSS3开发示例.docx Eclipse工程文件 SSH2.zip Zip包是Eclipse...