环境 :系统开发过程中,我们都曾实现过将系统元数据或字典表添加到缓存中,以便程序调用,减少数据库访问IO。
问题 :在用户通过前端页面更新系统字典表时,需手工刷新系统缓存,操作很不友好。
解决方案 :监听持久层DAO方法的调用,对于目标表的insert,update,delete操作进行相应的系统缓存更新。
示例环境 :Spring2.5 + iBatis + AspectJ
参考书目 :Spring 2.5 Aspect-Oriented Programming
Spring AOP自动代理的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" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
- <aop:aspectj-autoproxy/>
- </beans>
被监测类的代码:
- public interface ScDbInfoDAO {
- BigDecimal insert(ScDbInfo record);
- int updateByPrimaryKey(ScDbInfo record);
- int updateByPrimaryKeySelective(ScDbInfo record);
- List selectByExample(ScDbInfoExample example, String orderByClause);
- List selectByExample(ScDbInfoExample example);
- ScDbInfo selectByPrimaryKey(BigDecimal dbId);
- int deleteByExample(ScDbInfoExample example);
- int deleteByPrimaryKey(BigDecimal dbId);
- int selectCountByExample(ScDbInfoExample example);
- }
然后是AspectJ实现:
- import org.apache.log4j.Logger;
- import org.aspectj.lang.JoinPoint;
- import org.aspectj.lang.Signature;
- import org.aspectj.lang.annotation.AfterReturning;
- import org.aspectj.lang.annotation.Aspect;
- import org.springframework.stereotype.Service;
- /**
- * @author seraph
- *
- */
- @Service
- @Aspect
- public class JdbcSourceInterceptor {
- private static final Logger log = Logger.getLogger(JdbcSourceInterceptor.class);
- @AfterReturning(value="execution(* com.longtop.data.switching.db.dao.ScDbInfoDAO.*(..))", argNames="rtv", returning="rtv")
- public void afterInsertMethod(JoinPoint jp, Object rtv) throws Throwable {
- Signature signature = jp.getSignature();
- log.debug("DeclaringType:" + signature.getDeclaringType());
- log.debug("DeclaringTypeName:" + signature.getDeclaringTypeName());
- log.debug("Modifiers:" + signature.getModifiers());
- log.debug("Name:" + signature.getName());
- log.debug("LongString:" + signature.toLongString());
- log.debug("ShortString:" + signature.toShortString());
- for (int i = 0; i < jp.getArgs().length; i++) {
- Object arg = jp.getArgs()[i];
- if(null != arg) {
- log.debug("Args:" + arg.toString());
- }
- }
- log.debug("Return:" + rtv);
- }
- }
运行时的监测日志:
- JdbcSourceInterceptor - DeclaringType:class dao.impl.ScDbInfoDAOImpl
- JdbcSourceInterceptor - DeclaringTypeName:dao.impl.ScDbInfoDAOImpl
- JdbcSourceInterceptor - Modifiers:1
- JdbcSourceInterceptor - Name:selectByPrimaryKey
- JdbcSourceInterceptor - LongString:ScDbInfoDAOImpl.selectByPrimaryKey(BigDecimal)
- JdbcSourceInterceptor - ShortString:selectByPrimaryKey
- JdbcSourceInterceptor - Args:1
- JdbcSourceInterceptor - Return:ScDbInfo: [dbId=1, dbName=oracle, dbDesc=oracle驱动, dbType=2, dbIp=10.1.7.19, dbPortNo=1521, dbInstName=dc, dbUserName=cgst, dbPwd=cgst, maxConnNum=100, minConnNum=20, initConnNum=26]
通过以上的日志我们可以看出,@AfterReturning注释AOP中,通过JoinPoint和返回参数我们可以得到类运行时的所有相关信息,如通过方法名我们可以鉴别出是insert, update还是delete操作,针对不同的操作实现不同的处理方法,如调用缓存的add(),remove(),refresh()方法。我们还可以获取方法的调用参数及返回值,这极大的方便了我们对原业务逻辑的AOP处理。
一些相关概念:
- Aspect - 切面
- Pointcut - 切入点
- Joinpoint - 连接点
- Pointcut Designators (PCD)
Spring AOP中, 切入点(Pointcut)注释符在使用execution方法时以下的连接点(joinpoint)是可用的。
• execution
• within
• this
• target
• args
• @target
• @args
• @within
• @annotation
• bean
以下的切入点(pointcut)仅支持基于XML的Spring AOP配置,不支持AspectJ注释形式。如使用将会导致IllegalArgumentException异常。他们是:
• call
• get
• set
• preinitialization
• staticinitialization
• initialization
• handler
• adviceexecution
• withincode
• cflow
• cflowbelow
• if
• @this
• @withincode
Spring AOP 系统日志记录
AOP是Aspect Oriented Programming的缩写,意思是面向方面编程,AOP实际是GoF设计模式的延续
关于Spring AOP的一些术语
- 切面(Aspect) :在Spring AOP中,切面可以使用通用类或者在普通类中以@Aspect 注解(@AspectJ风格)来实现
- 连接点(Joinpoint) :在Spring AOP中一个连接点代表一个方法的执行
- 通知(Advice) :在切面的某个特定的连接点(Joinpoint)上执行的动作。通知有各种类型,其中包括"around"、"before”和"after"等通知。许多AOP框架,包括Spring,都是以拦截器做通知模型, 并维护一个以连接点为中心的拦截器链
- 切入点(Pointcut) :定义出一个或一组方法,当执行这些方法时可产生通知,Spring缺省使用AspectJ切入点语法。
通知类型
- 前置通知(@Before) :在某连接点(join point)之前执行的通知,但这个通知不能阻止连接点前的执行(除非它抛出一个异常)
- 返回后通知(@AfterReturning) :在某连接点(join point)正常完成后执行的通知:例如,一个方法没有抛出任何异常,正常返回
- 抛出异常后通知(@AfterThrowing) :方法抛出异常退出时执行的通知
- 后通知(@After) :当某连接点退出的时候执行的通知(不论是正常返回还是异常退出)
- 环绕通知(@Around) :包围一个连接点(join point)的通知,如方法调用。这是最强大的一种通知类型,环绕通知可以在方法调用前后完成自定义的行为,它也会选择是否继续执行连接点或直接返回它们自己的返回值或抛出异常来结束执行
@AspectJ风格的AOP配置
Spring AOP配置有两种风格:
- XML风格 = 采用声明形式实现Spring AOP
- AspectJ风格 = 采用注解形式实现Spring AOP
创建日志记录表(MySQL)
<span class="operator"><span class="keyword" style="font-weight:bold">CREATE</span> <span class="keyword" style="font-weight:bold">TABLE</span> <span class="string" style="color:#dd1144;">`t_log`</span> (
<span class="string" style="color:#dd1144;">`id`</span> bigint(<span class="number" style="color:#09999;">20</span>) unsigned <span class="keyword" style="font-weight:bold">NOT</span> <span class="keyword" style="font-weight:bold">NULL</span> AUTO_INCREMENT,
<span class="string" style="color:#dd1144;">`userid`</span> bigint(<span class="number" style="color:#09999;">20</span>) unsigned <span class="keyword" style="font-weight:bold">NOT</span> <span class="keyword" style="font-weight:bold">NULL</span>,
<span class="string" style="color:#dd1144;">`createdate`</span> datetime <span class="keyword" style="font-weight:bold">NOT</span> <span class="keyword" style="font-weight:bold">NULL</span> COMMENT <span class="string" style="color:#dd1144;">'创建日期'</span>,
<span class="string" style="color:#dd1144;">`content`</span> <span class="keyword" style="font-weight:bold">varchar</span>(<span class="number" style="color:#09999;">8000</span>) <span class="keyword" style="font-weight:bold">NOT</span> <span class="keyword" style="font-weight:bold">NULL</span> <span class="keyword" style="font-weight:bold">DEFAULT</span> <span class="string" style="color:#dd1144;">''</span> COMMENT <span class="string" style="color:#dd1144;">'日志内容'</span>,
<span class="string" style="color:#dd1144;">`operation`</span> <span class="keyword" style="font-weight:bold">varchar</span>(<span class="number" style="color:#09999;">250</span>) <span class="keyword" style="font-weight:bold">NOT</span> <span class="keyword" style="font-weight:bold">NULL</span> <span class="keyword" style="font-weight:bold">DEFAULT</span> <span class="string" style="color:#dd1144;">''</span> COMMENT <span class="string" style="color:#dd1144;">'用户所做的操作'</span>,
<span class="keyword" style="font-weight:bold">PRIMARY</span> <span class="keyword" style="font-weight:bold">KEY</span> (<span class="string" style="color:#dd1144;">`id`</span>)
) ENGINE=InnoDB <span class="keyword" style="font-weight:bold">DEFAULT</span> CHARSET=utf8;</span>
日志记录POJO类:
<strong><span class="keyword">package</span> com.hz.yiliao.orm;
<span class="keyword">import</span> java.io.Serializable;
<span class="keyword">import</span> java.util.Date;
<span class="javadoc" style="color:#999988;font-style:italic">/**
* 系统日志
* <span class="javadoctag">@author</span> Administrator
*
*/</span>
<span class="keyword">public</span> <span class="class" style="color:#445588;"><span class="keyword" style="color:#333333;">class</span> <span class="title">Log</span> <span class="keyword" style="color:#333333;">implements</span> <span class="title">Serializable</span>{</span>
<span class="indent"> </span><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">long</span> serialVersionUID = -<span class="number" style="color:#09999;">7372303516713218870</span>L;
<span class="indent"> </span>
<span class="indent"> </span><span class="keyword">private</span> Long id;<span class="comment" style="color:#999988;font-style:italic">//</span>
<span class="indent"> </span><span class="keyword">private</span> Long userId;<span class="comment" style="color:#999988;font-style:italic">//</span>
<span class="indent"> </span><span class="keyword">private</span> Date createDate;<span class="comment" style="color:#999988;font-style:italic">//创建日期</span>
<span class="indent"> </span><span class="keyword">private</span> String content;<span class="comment" style="color:#999988;font-style:italic">//日志内容</span>
<span class="indent"> </span><span class="keyword">private</span> String operation;<span class="comment" style="color:#999988;font-style:italic">//用户所做的操作</span>
<span class="indent"> </span>
<span class="indent"> </span><span class="comment" style="color:#999988;font-style:italic">//get set方法省略,自己生成</span>
<span class="indent"> </span>
<span class="indent"> </span>
}
</strong>
日志记录Mapper接口与XML配置文件:
<strong><span class="keyword">package</span> com.hz.yiliao.dao;
<span class="keyword">import</span> java.util.List;
<span class="keyword">import</span> java.util.Map;
<span class="keyword">import</span> com.hz.yiliao.orm.Log;
<span class="javadoc" style="color:#999988;font-style:italic">/**
* 系统日志接口
* <span class="javadoctag">@author</span> Administrator
*
*/</span>
<span class="keyword">public</span> <span class="class" style="color:#445588;"><span class="keyword" style="color:#333333;">interface</span> <span class="title">LogMapper</span> {</span>
<span class="indent"> </span><span class="javadoc" style="color:#999988;font-style:italic">/**
<span class="indent"> </span> * 新增
<span class="indent"> </span> * <span class="javadoctag">@param</span> log
<span class="indent"> </span> */</span>
<span class="indent"> </span><span class="keyword">public</span> <span class="keyword">void</span> insert(Log log);
<span class="indent"> </span>
}</strong>
LogMapper.xml配置文件
<strong><span class="pi" style="color:#999999;"><?xml version="1.0" encoding="UTF-8"?></span> <span class="doctype" style="color:#999999;"><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"></span> <span class="tag" style="color:#0080;font-weight:normal"><<span class="title">mapper</span> <span class="attribute" style="color:#08080;">namespace</span>=<span class="value" style="color:#dd1144;">"com.hz.yiliao.dao.LogMapper"</span>></span> <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">resultMap</span> <span class="attribute" style="color:#08080;">type</span>=<span class="value" style="color:#dd1144;">"com.hz.yiliao.orm.Log"</span> <span class="attribute" style="color:#08080;">id</span>=<span class="value" style="color:#dd1144;">"LogMapper"</span>></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">id</span> <span class="attribute" style="color:#08080;">property</span>=<span class="value" style="color:#dd1144;">"id"</span> <span class="attribute" style="color:#08080;">column</span>=<span class="value" style="color:#dd1144;">"id"</span>/></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">result</span> <span class="attribute" style="color:#08080;">property</span>=<span class="value" style="color:#dd1144;">"userId"</span> <span class="attribute" style="color:#08080;">column</span>=<span class="value" style="color:#dd1144;">"userid"</span> /></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">result</span> <span class="attribute" style="color:#08080;">property</span>=<span class="value" style="color:#dd1144;">"createDate"</span> <span class="attribute" style="color:#08080;">column</span>=<span class="value" style="color:#dd1144;">"createdate"</span> /></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">result</span> <span class="attribute" style="color:#08080;">property</span>=<span class="value" style="color:#dd1144;">"content"</span> <span class="attribute" style="color:#08080;">column</span>=<span class="value" style="color:#dd1144;">"content"</span> /></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">result</span> <span class="attribute" style="color:#08080;">property</span>=<span class="value" style="color:#dd1144;">"operation"</span> <span class="attribute" style="color:#08080;">column</span>=<span class="value" style="color:#dd1144;">"operation"</span> /></span> <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"></<span class="title">resultMap</span>></span> <span class="indent"> </span> <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">sql</span> <span class="attribute" style="color:#08080;">id</span>=<span class="value" style="color:#dd1144;">"LogSQL"</span>></span> <span class="indent"> </span><span class="indent"> </span>userid,createdate,content,operation <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"></<span class="title">sql</span>></span> <span class="indent"> </span> <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">insert</span> <span class="attribute" style="color:#08080;">id</span>=<span class="value" style="color:#dd1144;">"insert"</span> <span class="attribute" style="color:#08080;">parameterType</span>=<span class="value" style="color:#dd1144;">"com.hz.yiliao.orm.Log"</span> <span class="attribute" style="color:#08080;">useGeneratedKeys</span>=<span class="value" style="color:#dd1144;">"true"</span> <span class="attribute" style="color:#08080;">keyProperty</span>=<span class="value" style="color:#dd1144;">"id"</span> <span class="attribute" style="color:#08080;">keyColumn</span>=<span class="value" style="color:#dd1144;">"id"</span>></span> <span class="indent"> </span><span class="indent"> </span>insert into t_log(<span class="tag" style="color:#0080;font-weight:normal"><<span class="title">include</span> <span class="attribute" style="color:#08080;">refid</span>=<span class="value" style="color:#dd1144;">"LogSQL"</span>/></span>) value(#{userId},NOW(),#{content},#{operation}) <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"></<span class="title">insert</span>></span> <span class="indent"> </span> <span class="tag" style="color:#0080;font-weight:normal"></<span class="title">mapper</span>></span></strong>
日志记录Service层:
<strong><span class="keyword">package</span> com.hz.yiliao.bo;
<span class="keyword">import</span> java.util.List;
<span class="keyword">import</span> java.util.Map;
<span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;
<span class="keyword">import</span> org.springframework.stereotype.Service;
<span class="keyword">import</span> org.springframework.transaction.annotation.Transactional;
<span class="keyword">import</span> com.hz.yiliao.dao.LogMapper;
<span class="keyword">import</span> com.hz.yiliao.orm.AdminUser;
<span class="keyword">import</span> com.hz.yiliao.orm.Log;
<span class="javadoc" style="color:#999988;font-style:italic">/**
* 系统日志逻辑层
* <span class="javadoctag">@author</span> Administrator
*
*/</span>
<span class="annotation">@Service</span>
<span class="keyword">public</span> <span class="class" style="color:#445588;"><span class="keyword" style="color:#333333;">class</span> <span class="title">LogBO</span> {</span>
<span class="indent"> </span>
<span class="indent"> </span><span class="annotation">@Autowired</span>
<span class="indent"> </span><span class="keyword">private</span> LogMapper logMapper;
<span class="indent"> </span><span class="javadoc" style="color:#999988;font-style:italic">/**
<span class="indent"> </span> * 新增
<span class="indent"> </span> * <span class="javadoctag">@param</span> log
<span class="indent"> </span> */</span>
<span class="indent"> </span><span class="annotation">@Transactional</span>(<span class="string" style="color:#dd1144;">"transactionManager"</span>)
<span class="indent"> </span><span class="keyword">public</span> <span class="keyword">void</span> insertLog(Log log){
<span class="indent"> </span><span class="indent"> </span>logMapper.insert(log);
<span class="indent"> </span>}
<span class="indent"> </span>
<span class="indent"> </span>
}
</strong>
在MyBatis配置文件mybatis-config.xml中配置POJO,根据自己的要求配置,如果不知道怎么配置,看一下spring+mybatis整合
创建utils包,在utils包下创建切面类LogAspect:
<strong><span class="keyword">package</span> com.hz.yiliao.utils;
<span class="keyword">import</span> java.lang.reflect.Method;
<span class="keyword">import</span> org.aspectj.lang.JoinPoint;
<span class="keyword">import</span> org.aspectj.lang.annotation.AfterReturning;
<span class="keyword">import</span> org.aspectj.lang.annotation.Aspect;
<span class="keyword">import</span> org.aspectj.lang.annotation.Pointcut;
<span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;
<span class="keyword">import</span> com.hz.yiliao.bo.LogBO;
<span class="keyword">import</span> com.hz.yiliao.orm.Log;
<span class="javadoc" style="color:#999988;font-style:italic">/**
* 系统日志AOP
* <span class="javadoctag">@author</span> Administrator
*
*/</span>
<span class="annotation">@Aspect</span>
<span class="keyword">public</span> <span class="class" style="color:#445588;"><span class="keyword" style="color:#333333;">class</span> <span class="title">LogAspect</span> {</span>
<span class="indent"> </span><span class="annotation">@Autowired</span>
<span class="indent"> </span><span class="keyword">private</span> LogBO logBO;
<span class="indent"> </span>
<span class="indent"> </span><span class="javadoc" style="color:#999988;font-style:italic">/**
<span class="indent"> </span> * 添加业务逻辑方法切入点
<span class="indent"> </span> */</span>
<span class="indent"> </span><span class="annotation">@Pointcut</span>(<span class="string" style="color:#dd1144;">"execution(* com.hz.yiliao.bo.*.insert(..))"</span>)
<span class="indent"> </span><span class="keyword">public</span> <span class="keyword">void</span> insertCell(){}
<span class="indent"> </span>
<span class="indent"> </span><span class="javadoc" style="color:#999988;font-style:italic">/**
<span class="indent"> </span> * 修改业务逻辑方法切入点
<span class="indent"> </span> */</span>
<span class="indent"> </span><span class="annotation">@Pointcut</span>(<span class="string" style="color:#dd1144;">"execution(* com.hz.yiliao.bo.*.update(..))"</span>)
<span class="indent"> </span><span class="keyword">public</span> <span class="keyword">void</span> updateCell(){}
<span class="indent"> </span>
<span class="indent"> </span><span class="javadoc" style="color:#999988;font-style:italic">/**
<span class="indent"> </span> * 删除业务逻辑方法切入点
<span class="indent"> </span> */</span>
<span class="indent"> </span><span class="annotation">@Pointcut</span>(<span class="string" style="color:#dd1144;">"execution(* com.hz.yiliao.bo.*.delete(..))"</span>)
<span class="indent"> </span><span class="keyword">public</span> <span class="keyword">void</span> deleteCell(){}
<span class="indent"> </span>
<span class="indent"> </span><span class="javadoc" style="color:#999988;font-style:italic">/**
<span class="indent"> </span> * 添加操作日志(后置通知)
<span class="indent"> </span> * <span class="javadoctag">@param</span> joinPoint
<span class="indent"> </span> * <span class="javadoctag">@param</span> rtv
<span class="indent"> </span> */</span>
<span class="indent"> </span><span class="annotation">@SuppressWarnings</span>(<span class="string" style="color:#dd1144;">"unused"</span>)
<span class="indent"> </span><span class="annotation">@AfterReturning</span>(value=<span class="string" style="color:#dd1144;">"insertCell()"</span>,argNames=<span class="string" style="color:#dd1144;">"rtv"</span>, returning=<span class="string" style="color:#dd1144;">"rtv"</span>)
<span class="indent"> </span><span class="keyword">public</span> <span class="keyword">void</span> insertLog(JoinPoint joinPoint, Object rtv) <span class="keyword">throws</span> Throwable{
<span class="indent"> </span><span class="indent"> </span>Long userId = <span class="number" style="color:#09999;">1</span>L;
<span class="indent"> </span><span class="indent"> </span>
<span class="indent"> </span><span class="indent"> </span><span class="keyword">if</span>(userId == <span class="keyword">null</span>){<span class="comment" style="color:#999988;font-style:italic">//没有管理员登录 </span>
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="keyword">return</span> ;
<span class="indent"> </span><span class="indent"> </span>}
<span class="indent"> </span><span class="indent"> </span><span class="comment" style="color:#999988;font-style:italic">//判断参数 </span>
<span class="indent"> </span><span class="indent"> </span><span class="keyword">if</span>(joinPoint.getArgs() == <span class="keyword">null</span>){<span class="comment" style="color:#999988;font-style:italic">//没有参数 </span>
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="keyword">return</span> ;
<span class="indent"> </span><span class="indent"> </span>}
<span class="indent"> </span><span class="indent"> </span><span class="comment" style="color:#999988;font-style:italic">//获取方法名 </span>
<span class="indent"> </span><span class="indent"> </span>String methodName = joinPoint.getSignature().getName();
<span class="indent"> </span><span class="indent"> </span><span class="comment" style="color:#999988;font-style:italic">//获取操作内容</span>
<span class="indent"> </span><span class="indent"> </span>String opContent = optionContent(joinPoint.getArgs(),methodName);
<span class="indent"> </span><span class="indent"> </span>
<span class="indent"> </span><span class="indent"> </span>Log log = <span class="keyword">new</span> Log();
<span class="indent"> </span><span class="indent"> </span>log.setUserId(userId);
<span class="indent"> </span><span class="indent"> </span>log.setContent(opContent);
<span class="indent"> </span><span class="indent"> </span>log.setOperation(<span class="string" style="color:#dd1144;">"添加"</span>);
<span class="indent"> </span><span class="indent"> </span>logBO.insertLog(log);
<span class="indent"> </span>}
<span class="indent"> </span>
<span class="indent"> </span> <span class="javadoc" style="color:#999988;font-style:italic">/**
* 管理员修改操作日志(后置通知)
* <span class="javadoctag">@param</span> joinPoint
* <span class="javadoctag">@param</span> rtv
* <span class="javadoctag">@throws</span> Throwable
*/</span>
<span class="annotation">@SuppressWarnings</span>(<span class="string" style="color:#dd1144;">"unused"</span>)
<span class="indent"> </span><span class="annotation">@AfterReturning</span>(value=<span class="string" style="color:#dd1144;">"updateCell()"</span>, argNames=<span class="string" style="color:#dd1144;">"rtv"</span>, returning=<span class="string" style="color:#dd1144;">"rtv"</span>)
<span class="keyword">public</span> <span class="keyword">void</span> updateLog(JoinPoint joinPoint, Object rtv) <span class="keyword">throws</span> Throwable{
Long userId = <span class="number" style="color:#09999;">1</span>L;
<span class="keyword">if</span>(userId == <span class="keyword">null</span>){<span class="comment" style="color:#999988;font-style:italic">//没有登录 </span>
<span class="keyword">return</span>;
}
<span class="comment" style="color:#999988;font-style:italic">//判断参数 </span>
<span class="keyword">if</span>(joinPoint.getArgs() == <span class="keyword">null</span>){<span class="comment" style="color:#999988;font-style:italic">//没有参数 </span>
<span class="keyword">return</span>;
}
<span class="comment" style="color:#999988;font-style:italic">//获取方法名 </span>
String methodName = joinPoint.getSignature().getName();
<span class="comment" style="color:#999988;font-style:italic">//获取操作内容 </span>
String opContent = optionContent(joinPoint.getArgs(), methodName);
<span class="comment" style="color:#999988;font-style:italic">//创建日志对象 </span>
Log log = <span class="keyword">new</span> Log();
<span class="indent"> </span><span class="indent"> </span>log.setUserId(userId);
<span class="indent"> </span><span class="indent"> </span>log.setContent(opContent);
log.setOperation(<span class="string" style="color:#dd1144;">"修改"</span>);<span class="comment" style="color:#999988;font-style:italic">//操作 </span>
logBO.insertLog(log);
}
<span class="javadoc" style="color:#999988;font-style:italic">/**
* 删除操作
* <span class="javadoctag">@param</span> joinPoint
* <span class="javadoctag">@param</span> rtv
*/</span>
<span class="annotation">@SuppressWarnings</span>(<span class="string" style="color:#dd1144;">"unused"</span>)
<span class="indent"> </span><span class="annotation">@AfterReturning</span>(value=<span class="string" style="color:#dd1144;">"deleteCell()"</span>,argNames=<span class="string" style="color:#dd1144;">"rtv"</span>, returning=<span class="string" style="color:#dd1144;">"rtv"</span>)
<span class="keyword">public</span> <span class="keyword">void</span> deleteLog(JoinPoint joinPoint, Object rtv) <span class="keyword">throws</span> Throwable{
Long userId = <span class="number" style="color:#09999;">1</span>L;
<span class="keyword">if</span>(userId == <span class="keyword">null</span>){<span class="comment" style="color:#999988;font-style:italic">//没有登录 </span>
<span class="keyword">return</span>;
}
<span class="comment" style="color:#999988;font-style:italic">//判断参数 </span>
<span class="keyword">if</span>(joinPoint.getArgs() == <span class="keyword">null</span>){<span class="comment" style="color:#999988;font-style:italic">//没有参数 </span>
<span class="keyword">return</span>;
}
<span class="comment" style="color:#999988;font-style:italic">//获取方法名 </span>
String methodName = joinPoint.getSignature().getName();
StringBuffer rs = <span class="keyword">new</span> StringBuffer();
<span class="indent"> </span><span class="indent"> </span>rs.append(methodName);
<span class="indent"> </span><span class="indent"> </span>String className = <span class="keyword">null</span>;
<span class="indent"> </span><span class="indent"> </span><span class="keyword">for</span>(Object info : joinPoint.getArgs()){
<span class="comment" style="color:#999988;font-style:italic">//获取对象类型</span>
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>className = info.getClass().getName();
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>className = className.substring(className.lastIndexOf(<span class="string" style="color:#dd1144;">"."</span>) + <span class="number" style="color:#09999;">1</span>);
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>rs.append(<span class="string" style="color:#dd1144;">"[参数1,类型:"</span> + className + <span class="string" style="color:#dd1144;">",值:(id:"</span> + joinPoint.getArgs()[<span class="number" style="color:#09999;">0</span>]+<span class="string" style="color:#dd1144;">")"</span>);
}
<span class="comment" style="color:#999988;font-style:italic">//创建日志对象 </span>
Log log = <span class="keyword">new</span> Log();
<span class="indent"> </span><span class="indent"> </span>log.setUserId(userId);
<span class="indent"> </span><span class="indent"> </span>log.setContent(rs.toString());
log.setOperation(<span class="string" style="color:#dd1144;">"删除"</span>);<span class="comment" style="color:#999988;font-style:italic">//操作 </span>
logBO.insertLog(log);
}
<span class="indent"> </span>
<span class="indent"> </span><span class="javadoc" style="color:#999988;font-style:italic">/**
<span class="indent"> </span> * 使用Java反射来获取被拦截方法(insert、update)的参数值,
* 将参数值拼接为操作内容
<span class="indent"> </span> * <span class="javadoctag">@param</span> args
<span class="indent"> </span> * <span class="javadoctag">@param</span> mName
<span class="indent"> </span> * <span class="javadoctag">@return</span>
<span class="indent"> </span> */</span>
<span class="indent"> </span><span class="keyword">public</span> String optionContent(Object[] args, String mName){
<span class="indent"> </span><span class="indent"> </span><span class="keyword">if</span>(args == <span class="keyword">null</span>){
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="keyword">return</span> <span class="keyword">null</span>;
<span class="indent"> </span><span class="indent"> </span>}
<span class="indent"> </span><span class="indent"> </span>StringBuffer rs = <span class="keyword">new</span> StringBuffer();
<span class="indent"> </span><span class="indent"> </span>rs.append(mName);
<span class="indent"> </span><span class="indent"> </span>String className = <span class="keyword">null</span>;
<span class="indent"> </span><span class="indent"> </span><span class="keyword">int</span> index = <span class="number" style="color:#09999;">1</span>;
<span class="indent"> </span><span class="indent"> </span><span class="comment" style="color:#999988;font-style:italic">//遍历参数对象 </span>
<span class="indent"> </span><span class="indent"> </span><span class="keyword">for</span>(Object info : args){
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="comment" style="color:#999988;font-style:italic">//获取对象类型</span>
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>className = info.getClass().getName();
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>className = className.substring(className.lastIndexOf(<span class="string" style="color:#dd1144;">"."</span>) + <span class="number" style="color:#09999;">1</span>);
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>rs.append(<span class="string" style="color:#dd1144;">"[参数"</span>+index+<span class="string" style="color:#dd1144;">",类型:"</span> + className + <span class="string" style="color:#dd1144;">",值:"</span>);
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="comment" style="color:#999988;font-style:italic">//获取对象的所有方法</span>
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>Method[] methods = info.getClass().getDeclaredMethods();
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="comment" style="color:#999988;font-style:italic">// 遍历方法,判断get方法 </span>
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="keyword">for</span>(Method method : methods){
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>String methodName = method.getName();
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="comment" style="color:#999988;font-style:italic">// 判断是不是get方法</span>
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="keyword">if</span>(methodName.indexOf(<span class="string" style="color:#dd1144;">"get"</span>) == -<span class="number" style="color:#09999;">1</span>){<span class="comment" style="color:#999988;font-style:italic">//不是get方法 </span>
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="keyword">continue</span>;<span class="comment" style="color:#999988;font-style:italic">//不处理</span>
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>}
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>Object rsValue = <span class="keyword">null</span>;
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="keyword">try</span>{
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="comment" style="color:#999988;font-style:italic">// 调用get方法,获取返回值</span>
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>rsValue = method.invoke(info);
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>}<span class="keyword">catch</span> (Exception e) {
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="keyword">continue</span>;
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>}
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="comment" style="color:#999988;font-style:italic">//将值加入内容中</span>
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>rs.append(<span class="string" style="color:#dd1144;">"("</span> + methodName+ <span class="string" style="color:#dd1144;">":"</span> + rsValue + <span class="string" style="color:#dd1144;">")"</span>);
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>}
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>rs.append(<span class="string" style="color:#dd1144;">"]"</span>);
<span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>index ++;
<span class="indent"> </span><span class="indent"> </span>}
<span class="indent"> </span><span class="indent"> </span><span class="keyword">return</span> rs.toString();
<span class="indent"> </span>}
<span class="indent"> </span>
}
</strong>
在applicationContext.xml中加入新的配置
<span style="font-weight:bold"><span class="pi" style="color:#999999;"><?xml version="1.0" encoding="UTF-8"?></span> <span class="tag" style="color:#0080;font-weight:normal"><<span class="title">beans</span> <span class="attribute" style="color:#08080;">xmlns</span>=<span class="value" style="color:#dd1144;">"http://www.springframework.org/schema/beans"</span> <span class="indent"> </span><span class="indent"> </span> <span class="attribute" style="color:#08080;">xmlns:mvc</span>=<span class="value" style="color:#dd1144;">"http://www.springframework.org/schema/mvc"</span> <span class="indent"> </span><span class="indent"> </span> <span class="attribute" style="color:#08080;">xmlns:xsi</span>=<span class="value" style="color:#dd1144;">"http://www.w3.org/2001/XMLSchema-instance"</span> <span class="indent"> </span><span class="indent"> </span> <span class="attribute" style="color:#08080;">xmlns:context</span>=<span class="value" style="color:#dd1144;">"http://www.springframework.org/schema/context"</span> <span class="indent"> </span><span class="indent"> </span> <span class="attribute" style="color:#08080;">xmlns:aop</span>=<span class="value" style="color:#dd1144;">"http://www.springframework.org/schema/aop"</span> <span class="indent"> </span><span class="indent"> </span> <span class="attribute" style="color:#08080;">xmlns:tx</span>=<span class="value" style="color:#dd1144;">"http://www.springframework.org/schema/tx"</span> <span class="indent"> </span><span class="indent"> </span> <span class="attribute" style="color:#08080;">xmlns:jee</span>=<span class="value" style="color:#dd1144;">"http://www.springframework.org/schema/jee"</span> <span class="indent"> </span><span class="indent"> </span> <span class="attribute" style="color:#08080;">xsi:schemaLocation</span>=<span class="value" style="color:#dd1144;">" <span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>http://www.springframework.org/schema/beans <span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>http://www.springframework.org/schema/beans/spring-beans-3.0.xsd <span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>http://www.springframework.org/schema/context <span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>http://www.springframework.org/schema/context/spring-context-3.0.xsd <span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>http://www.springframework.org/schema/mvc <span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd <span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>http://www.springframework.org/schema/aop <span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>http://www.springframework.org/schema/aop/spring-aop-3.0.xsd <span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>http://www.springframework.org/schema/tx <span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>http://www.springframework.org/schema/tx/spring-tx-3.0.xsd <span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>http://www.springframework.org/schema/jee <span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span>http://www.springframework.org/schema/jee/spring-tx-3.0.xsd"</span>></span> <span class="comment" style="color:#999988;font-style:italic"><!-- 加入Aspectj配置 --></span> <span class="indent"> </span> <span class="tag" style="color:#0080;font-weight:normal"><<span class="title">aop:aspectj-autoproxy</span> /></span> <span class="indent"> </span> <span class="tag" style="color:#0080;font-weight:normal"><<span class="title">bean</span> <span class="attribute" style="color:#08080;">id</span>=<span class="value" style="color:#dd1144;">"logAspect"</span> <span class="attribute" style="color:#08080;">class</span>=<span class="value" style="color:#dd1144;">"com.hz.yiliao.utils.LogAspect"</span> /></span> <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">context:component-scan</span> <span class="attribute" style="color:#08080;">base-package</span>=<span class="value" style="color:#dd1144;">"com.hz.yiliao.bo,com.hz.yiliao.orm"</span> /></span> <span class="indent"> </span> <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">bean</span> <span class="attribute" style="color:#08080;">id</span>=<span class="value" style="color:#dd1144;">"yiliaoDataSource"</span> <span class="attribute" style="color:#08080;">class</span>=<span class="value" style="color:#dd1144;">"org.apache.commons.dbcp.BasicDataSource"</span> <span class="attribute" style="color:#08080;">destroy-method</span>=<span class="value" style="color:#dd1144;">"close"</span>></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">property</span> <span class="attribute" style="color:#08080;">name</span>=<span class="value" style="color:#dd1144;">"driverClassName"</span> <span class="attribute" style="color:#08080;">value</span>=<span class="value" style="color:#dd1144;">"com.mysql.jdbc.Driver"</span> /></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">property</span> <span class="attribute" style="color:#08080;">name</span>=<span class="value" style="color:#dd1144;">"url"</span> <span class="attribute" style="color:#08080;">value</span>=<span class="value" style="color:#dd1144;">"jdbc:mysql://localhost:3306/yiliao?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull"</span> /></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">property</span> <span class="attribute" style="color:#08080;">name</span>=<span class="value" style="color:#dd1144;">"username"</span> <span class="attribute" style="color:#08080;">value</span>=<span class="value" style="color:#dd1144;">"root"</span> /></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">property</span> <span class="attribute" style="color:#08080;">name</span>=<span class="value" style="color:#dd1144;">"password"</span> <span class="attribute" style="color:#08080;">value</span>=<span class="value" style="color:#dd1144;">"root"</span> /></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">property</span> <span class="attribute" style="color:#08080;">name</span>=<span class="value" style="color:#dd1144;">"defaultAutoCommit"</span> <span class="attribute" style="color:#08080;">value</span>=<span class="value" style="color:#dd1144;">"false"</span> /></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">property</span> <span class="attribute" style="color:#08080;">name</span>=<span class="value" style="color:#dd1144;">"timeBetweenEvictionRunsMillis"</span> <span class="attribute" style="color:#08080;">value</span>=<span class="value" style="color:#dd1144;">"3600000"</span> /></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">property</span> <span class="attribute" style="color:#08080;">name</span>=<span class="value" style="color:#dd1144;">"minEvictableIdleTimeMillis"</span> <span class="attribute" style="color:#08080;">value</span>=<span class="value" style="color:#dd1144;">"3600000"</span> /></span> <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"></<span class="title">bean</span>></span> <span class="indent"> </span> <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">bean</span> <span class="attribute" style="color:#08080;">id</span>=<span class="value" style="color:#dd1144;">"yiliaoSessionFactory"</span> <span class="attribute" style="color:#08080;">class</span>=<span class="value" style="color:#dd1144;">"org.mybatis.spring.SqlSessionFactoryBean"</span>></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">property</span> <span class="attribute" style="color:#08080;">name</span>=<span class="value" style="color:#dd1144;">"dataSource"</span> <span class="attribute" style="color:#08080;">ref</span>=<span class="value" style="color:#dd1144;">"yiliaoDataSource"</span> /></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">property</span> <span class="attribute" style="color:#08080;">name</span>=<span class="value" style="color:#dd1144;">"typeAliasesPackage"</span> <span class="attribute" style="color:#08080;">value</span>=<span class="value" style="color:#dd1144;">"com.hz.yiliao.orm"</span> /></span> <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"></<span class="title">bean</span>></span> <span class="indent"> </span> <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">bean</span> <span class="attribute" style="color:#08080;">id</span>=<span class="value" style="color:#dd1144;">"mailSender"</span> <span class="attribute" style="color:#08080;">class</span>=<span class="value" style="color:#dd1144;">"com.hz.yiliao.utils.MailSender"</span>></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">property</span> <span class="attribute" style="color:#08080;">name</span>=<span class="value" style="color:#dd1144;">"javaMailSender"</span> <span class="attribute" style="color:#08080;">ref</span>=<span class="value" style="color:#dd1144;">"javaMailSender"</span> /></span> <span class="indent"> </span> <span class="tag" style="color:#0080;font-weight:normal"></<span class="title">bean</span>></span> <span class="indent"> </span> <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">bean</span> <span class="attribute" style="color:#08080;">id</span>=<span class="value" style="color:#dd1144;">"javaMailSender"</span> <span class="attribute" style="color:#08080;">class</span>=<span class="value" style="color:#dd1144;">"org.springframework.mail.javamail.JavaMailSenderImpl"</span>></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">property</span> <span class="attribute" style="color:#08080;">name</span>=<span class="value" style="color:#dd1144;">"host"</span> <span class="attribute" style="color:#08080;">value</span>=<span class="value" style="color:#dd1144;">"smtp.163.com"</span> /></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">property</span> <span class="attribute" style="color:#08080;">name</span>=<span class="value" style="color:#dd1144;">"username"</span> <span class="attribute" style="color:#08080;">value</span>=<span class="value" style="color:#dd1144;">"yiliao_2014@163.com"</span> /></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">property</span> <span class="attribute" style="color:#08080;">name</span>=<span class="value" style="color:#dd1144;">"password"</span> <span class="attribute" style="color:#08080;">value</span>=<span class="value" style="color:#dd1144;">"yiliao2014"</span> /></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">property</span> <span class="attribute" style="color:#08080;">name</span>=<span class="value" style="color:#dd1144;">"defaultEncoding"</span> <span class="attribute" style="color:#08080;">value</span>=<span class="value" style="color:#dd1144;">"UTF-8"</span> /></span> <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"></<span class="title">bean</span>></span> <span class="tag" style="color:#0080;font-weight:normal"><<span class="title">import</span> <span class="attribute" style="color:#08080;">resource</span>=<span class="value" style="color:#dd1144;">"mybatis-config.xml"</span> /></span> <span class="tag" style="color:#0080;font-weight:normal"><<span class="title">bean</span> <span class="attribute" style="color:#08080;">id</span>=<span class="value" style="color:#dd1144;">"transactionManager"</span> <span class="attribute" style="color:#08080;">class</span>=<span class="value" style="color:#dd1144;">"org.springframework.jdbc.datasource.DataSourceTransactionManager"</span>></span> <span class="indent"> </span><span class="indent"> </span> <span class="tag" style="color:#0080;font-weight:normal"><<span class="title">property</span> <span class="attribute" style="color:#08080;">name</span>=<span class="value" style="color:#dd1144;">"dataSource"</span>></span> <span class="indent"> </span><span class="indent"> </span> <span class="tag" style="color:#0080;font-weight:normal"><<span class="title">ref</span> <span class="attribute" style="color:#08080;">local</span>=<span class="value" style="color:#dd1144;">"yiliaoDataSource"</span> /></span> <span class="indent"> </span><span class="indent"> </span> <span class="tag" style="color:#0080;font-weight:normal"></<span class="title">property</span>></span> <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"></<span class="title">bean</span>></span> <span class="indent"> </span> <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">mvc:interceptors</span>></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">mvc:interceptor</span>></span> <span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">mvc:mapping</span> <span class="attribute" style="color:#08080;">path</span>=<span class="value" style="color:#dd1144;">"/**"</span> /></span> <span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">bean</span> <span class="attribute" style="color:#08080;">class</span>=<span class="value" style="color:#dd1144;">"com.hz.yiliao.filt.YiliaoSysInterceptor"</span> /></span> <span class="indent"> </span><span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"></<span class="title">mvc:interceptor</span>></span> <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"></<span class="title">mvc:interceptors</span>></span> <span class="indent"> </span> <span class="indent"> </span><span class="tag" style="color:#0080;font-weight:normal"><<span class="title">tx:annotation-driven</span> <span class="attribute" style="color:#08080;">transaction-manager</span>=<span class="value" style="color:#dd1144;">"transactionManager"</span> <span class="attribute" style="color:#08080;">proxy-target-class</span>=<span class="value" style="color:#dd1144;">"true"</span> /></span> <span class="tag" style="color:#0080;font-weight:normal"></<span class="title">beans</span>></span> </span>
配置成功后分别进行登录、添加、修改、删除 等 操作,日志记录表的内容如下: