springAOP,属于类的增强,这个我还没想好用在哪,但是先实现
Step11:
这里先贴MyAspect.java,这个切面的代码
package com.ssmlogin.aop; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.springframework.stereotype.Component; /** * * @ClassName: MyAspect * @Description: TODO(这里用一句话描述这个类的作用) * @author A18ccms a18ccms_gmail_com * @date 2018年4月20日 下午12:56:59 * execution(<修饰符模式>?<返回类型模式><方法名模式>(<参数模式>)<异常模式>?) * 除了返回类型模式、方法名模式和参数模式外,其它项都是可选的。 */ @Aspect //表示当前是切面 public class MyAspect { // 修饰符模式 返回类型模式 方法名模式(参数模式) // @Before("execution(* com.ssmlogin.controller..*.*(..))") @Before("execution(* * ..LoginService.*(..))") public void before() { System.out.println("执行前置方法通知"); } @Before("execution(* * ..LoginController.*(..))") public void beforeCheckToken(){ System.out.println("调用方法之前。。。。"); } }
这里看到采用的是注释的方式。
这里注意,注册的地方,是在spring-mvc中不是spring,因为在spring中注册之后,spring-mvc并吃不到,也就是controller并吃不到。。。绝望
<!-- 注册切面 --> <bean id="MyAspect" class="com.ssmlogin.aop.MyAspect" /> <aop:aspectj-autoproxy />
这里的重点当然是execution表达式了,可以再看看。
至此,SSM整合完毕并实现了一个简单的登录注册功能,之后的话,是因为我要写一个微信小程序,所以学一学SSM,用来做后台。
如果我的内容在哪里有问题,欢迎私信指正。