es">
< list>
< value>edujlufuliangdomainBook.hbm.xml< /value>
< /list>
< /property>
< /bean>
< /beans>
applicationContext-dao.xml:
< ?xml version="1.0" encoding="UTF-8"?>
< beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
< bean id="bookDAO" class="edu.jlu.fuliang.dao.BookDAO">
< property name="sessionFactory">
< ref bean="sessionFactory" />
< /property>
< /bean>
< /beans>
谈谈对Struts多模块的认识(3)
时间:2011-03-14
接下来我们来写我们的Service层:
edu.jlu.fuliang.service.BookManageService.java
package edu.jlu.fuliang.service;
import java.util.List;
import edu.jlu.fuliang.domain.Book;
public interface BookManageService {
public List< Book> getAllBooks();
public List< Book> getBookByName(String name);
public void updateBook(Book book);
public void addBook(Book book);
public void deleteBook(long id);
}
edu.jlu.fuliang.service.impl.BookManageServiceImpl.java:
package edu.jlu.fuliang.serviceImpl;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.jlu.fuliang.dao.BookDAO;
import edu.jlu.fuliang.domain.Book;
import edu.jlu.fuliang.service.BookManageService;
public class BookManageServiceImpl implements BookManageService{
private static final Log log = LogFactory.getLog(BookManageServiceImpl.class);
private BookDAO bookDAO;
@Override
public void addBook(Book book) {
bookDAO.save(book);
}
@Override
public void deleteBook(long id) {
Book book = bookDAO.findById(id);
bookDAO.delete(book);
}
@Override
public List< Book> getAllBooks() {
return bookDAO.findAll();
}
@Override
public List< Book> getBookByName(String name) {
return bookDAO.findByName(name);
}
@Override
public void updateBook(Book book) {
log.info(book);
bookDAO.attachDirty(book);
}
public BookDAO getBookDAO() {
return bookDAO;
}
public void setBookDAO(BookDAO bookDAO) {
this.bookDAO = bookDAO;
}
}
然后我们来配置Service和事务:
applicationContext-service.xml:
< ?xml version="1.0" encoding="UTF-8"?>
< beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
< bean id="bookManageServiceTarget" class="edu.jlu.fuliang.serviceImpl
.BookManageServiceImpl">
< property name="bookDAO">
< ref bean="bookDAO"/>
< /property>
< /bean>
< bean id="transactionManager" class="org.springframework.orm.hibern
|