日期:2014-05-17 浏览次数:20728 次
<action name="book" class="bookAction"> <result name="add">book/addBook.jsp</result> <result name="addSuccess">book/addSuccess.jsp</result> <result name="modify">book/modifyBook.jsp</result> <result name="del">book/delBook.jsp</result> <!--//error后返回到error action,在结果页面里使用struts标签读取error值 --></action> <action name="index" class="indexAction"> <result name="success">index.jsp</result> </action>
@Component("bookAction") @Scope(value="prototype") public class BookAction extends ActionSupport implements ModelDriven<BookDTO>{ private BookDTO bookDTO = new BookDTO(); private BookService bookService; public BookService getBookService() { return bookService; } @Resource(name="bookService") public void setBookService(BookService bookService) { this.bookService = bookService; } public BookDTO getBookDTO() { return bookDTO; } public void setBookDTO(BookDTO bookDTO) { this.bookDTO = bookDTO; } public String add() throws Exception{ System.out.println("add"); return "add"; } }
<?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <context:annotation-config /> <aop:aspectj-autoproxy /> <context:component-scan base-package="localhost.lms.aop"></context:component-scan> <context:component-scan base-package="localhost.lms.service.impl" /> <context:component-scan base-package="localhost.lms.dao.impl" /> <context:component-scan base-package="localhost.lms.action"></context:component-scan> </beans>
@Aspect @Component("beanInteceptor") public class BeanInteceptor{ @Pointcut("execution(public * localhost.lms.action..*(..))") public void myMethod() {} @Around("myMethod()") //环绕通知 public Object around(ProceedingJoinPoint pjp) throws Throwable {