1.需要在应用程序的classpath中引入两个AspectJ库:aspectjweaver.jar 和 aspectjrt.jar。
2.servlet.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:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
//自动扫描包
<context:component-scan base-package="test.web.controller" />
</beans>
3.java
@AfterReturning("execution(* test.service.*.save(..))")
public void afterSaveAdviceDo(JoinPoint joinPoint) {
try {
Log entity = new Log();
String content = "";
//获取save的实体;
Object object = joinPoint.getArgs()[0];
content = _buildContentByReflex(object, Constants.SYS_ACTION_SAVE);
Administrator admin = AspectHelper.getCurrentAdministrator(object);
SystemInfo info = new SystemInfo();
info.setCreateDate(new Date());
info.setCreateUser(admin);
info.setLastModifyDate(new Date());
info.setLastModifyUser(admin);
entity.setSystemInfo(info);
entity.setContent(content);
logService.write(entity);
} catch (Exception e) {
if (log.isErrorEnabled())
log.error(e, e);
}
}
865

被折叠的 条评论
为什么被折叠?



