17Aspectij
17Aspectij-2018/07/31
- 1.Aspectj基于xml
- 前置通知
- method : 通知,及方法名
- pointcut :切入点表达式,此表达式只能当前通知使用。
- pointcut-ref : 切入点引用,可以与其他通知共享切入点。
- 通知方法格式:public void myBefore(JoinPoint joinPoint){参数1:org.aspectj.lang.JoinPoint } 用于描述连接点(目标方法),获得目标方法名等
- 后置通知:目标方法后执行,获得返回值
- 通知方法格式:public void myAfterReturning(JoinPoint joinPoint,Object ret){
- 参数1:连接点描述
- 参数2:类型Object,参数名 returning="ret" 配置的
- 通知方法格式:public void myAfterReturning(JoinPoint joinPoint,Object ret){
- 环绕通知
- 通知方法格式:public Object myAround(ProceedingJoinPoint joinPoint) throws Throwable{
- 返回值类型:Object
- 方法名:任意
- 参数:org.aspectj.lang.ProceedingJoinPoint
- 抛出异常
- 执行目标方法:Object obj = joinPoint.proceed();
- 通知方法格式:public Object myAround(ProceedingJoinPoint joinPoint) throws Throwable{
- 抛出异常
- <aop:after-throwing method="" pointcut-ref="" throwing=""/>
- throwing :通知方法的第二个参数名称
- 通知方法格式:public void myAfterThrowing(JoinPoint joinPoint,Throwable e){
- 参数1:连接点描述对象
- 参数2:获得异常信息,类型Throwable ,参数名由throwing="e" 配置
- <aop:after-throwing method="" pointcut-ref="" throwing=""/>
- 前置通知
- 2.注解在方法前面注解
- 声明公共切入点
- @Pointcut("execution(* com.itheima.daspect.banno.UserServiceImpl.*(..))")private void myPointCut(){}
- @Before(value="myPointCut()")value可以省略
- @AfterReturning(value="myPointCut()" ,returning="ret")
- @Around("myPointCut()")
- @AfterThrowing(value="execution(* com.itheima.daspect.banno.UserServiceImpl.*(..))" ,throwing="e")
- 声明公共切入点
- 3.JdbcTemplate
- 创建数据源(连接池) dbcp
BasicDataSource dataSource = new BasicDataSource();
// 基本4项
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/ee19springday02");
dataSource.setUsername("root");
dataSource.setPassword("1234"); - 创建模板
JdbcTemplate jdbcTemplate = new JdbcTemplate();
jdbcTemplate.setDataSource(dataSource); - 通过api操作
jdbcTemplate.update("insert into t_user(username,password) values(?,?);", "tom","998");
- 创建数据源(连接池) dbcp
- 4.传播行为:在两个业务之间如何共享事务
- PROPAGATION_REQUIRED , required , 必须 【默认值】 支持当前事务,A如果有事务,B将使用该事务。 如果A没有事务,B将创建一个新的事务。
- PROPAGATIONREQUIRESNEW , requires_new ,必须新的 如果A有事务,将A的事务挂起,B创建一个新的事务 如果A没有事务,B创建一个新的事务
- PROPAGATION_NESTED ,nested ,嵌套 A和B底层采用保存点机制,形成嵌套事务。
- 5.手动管理事务
- 1.service 需要获得 TransactionTemplate
- 2.spring 配置模板,并注入给service
- 3.模板需要注入事务管理器
- 4.配置事务管理器:DataSourceTransactionManager ,需要注入DataSource
17Aspectij的更多相关文章
随机推荐
- cc1: error: bad value (armv5) for -march= switch【转】
本文转载自:https://stackoverflow.com/questions/23871924/cc1-error-bad-value-armv5-for-march-switch Ask Qu ...
- docker映射端口与ssh访问或容器访问
映射端口 -d 后台执行 -p映射端口 --privileged 可以使用systemctl # docker run --privileged -d -p 9000:80 jiqing9006/ce ...
- Mac下搭建react native开发环境
安装必需软件 Homebrew Homebrew, Mac系统的包管理器,用于安装NodeJS和一些其他必需的工具软件. /usr/bin/ruby -e "$(curl -fsSL htt ...
- sql加一个%号是什么意思
sql%notfound 是异常SQL%ROWCOUNT SQL语句执行影响的行数SQL%FOUND SQL语句是否成功执行SQL%NOTFOUND SQL语句是否成功执行SQL%ISOPEN 游标是 ...
- JQuery 日期选择框
一 jeDate日期控件,关于官方的文档请查看: http://www.jayui.com/jedate/ 1 引入js文件 <script type="text/javascr ...
- 响应在此上下文中不可用 asp.net
(一)实例1: 在asp.net程序中添加了一个 类.cs 如下 using System; using System.Collections; using System.ComponentModel ...
- 17.EXTJs 中icon 与iconCls的区别及用法!
转自:https://blog.csdn.net/u013890437/article/details/38315717?utm_source=blogxgwz7
- jQuery:has()和jQuery:contains()及jQuery:empty
jQuery:has()和jQuery:contains()两个方法比较类似.不同点在于: has是判断标签的 contains是判断文本的 1.jQuery:has() <div>< ...
- 3-1 todolist功能开发
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- E20171228-hm
traverse n. 穿过; 横贯,横切; 横木; [建] 横梁; vt. 通过; 横越,横贯; [法] 否认,反驳; [木工] 横刨;