Posted on 2007-09-30 09:50
诗特林 阅读(13698)
评论(4) 编辑 收藏 所属分类:
Struts
Struts2+Spring2+Hibernate3 web应用示例(三)
五、 业务逻辑层
在业务逻辑层需要认真思考每个业务逻辑所能用到的持久层对象和DAO。DAO层之上是业务逻辑层,DAO类可以有很多个,但业务逻辑类应该只有一个,可以在业务逻辑类中调用各个DAO类进行操作。
1、创建服务接口类IBookService
1、 创建服务接口类IBookService
package com.sterning.books.services.iface;

import java.util.List;

import com.sterning.books.model.Books;


public interface IBooksService
{
List getAll();//获得所有记录
List getBooks(int pageSize, int startRow);//获得所有记录
int getRows();//获得总行数
int getRows(String fieldname,String value);//获得总行数
List queryBooks(String fieldname,String value);//根据条件查询
List getBooks(String fieldname,String value,int pageSize, int startRow);//根据条件查询
Books getBook(String bookId);//根据ID获得记录
String getMaxID();//获得最大ID值
void addBook(Books pd);//添加记录
void updateBook(Books pd);//修改记录
void deleteBook(String bookId);//删除记录
}

com.sterning.books.services.iface.IBookService.java
2、实现此接口类:BookService:
package com.sterning.books.services;

import java.util.List;

import com.sterning.books.dao.iface.BooksDao;
import com.sterning.books.model.Books;
import com.sterning.books.services.iface.IBooksService;


public class BooksService implements IBooksService
{
private BooksDao booksDao;

public BooksService()
{}

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

public void addBook(Books book)
{
booksDao.addBook(book);
}


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

public void deleteBook(String bookId)
{
Books book=booksDao.getBook(bookId);
booksDao.deleteBook(book);
}


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

public List getAll()
{
return booksDao.getAll();
}

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

public int getRows()
{
return booksDao.getRows();
}

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

public List getBooks(int pageSize, int startRow)
{
return booksDao.getBooks(pageSize, startRow);
}


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

public Books getBook(String bookId)
{
return booksDao.getBook(bookId);
}


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

public String getMaxID()
{
return booksDao.getMaxID();
}


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

public void updateBook(Books book)
{
booksDao.updateBook(book);
}


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

public List queryBooks(String fieldname,String value)
{
return booksDao.queryBooks(fieldname, value);
}

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

public int getRows(String fieldname,String value)
{
return booksDao.getRows(fieldname, value);
}

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

public List getBooks(String fieldname,String value,int pageSize, int startRow)
{
return booksDao.getBooks(fieldname, value,pageSize,startRow);
}


public BooksDao getBooksDao()
{
return booksDao;
}


public void setBooksDao(BooksDao booksDao)
{
this.booksDao = booksDao;
}

}

com.sterning.books.services.BookService.java
未完待续 。。。。。。