javaEEday12-AOP进阶-切入点表达式-execution---3
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
package com.inmind.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface MyLog {
|
||||||
|
}
|
||||||
@@ -22,11 +22,11 @@ public class MyAspect6 {
|
|||||||
// @Pointcut("execution(* delete*(..))")//此处表示所有delete开头的方法
|
// @Pointcut("execution(* delete*(..))")//此处表示所有delete开头的方法
|
||||||
/*接下来有个小需求:需要匹配deptList和deleteDept这2个方法,它们名称上没有相同的地方,参数列表也不同,一个有返回值,
|
/*接下来有个小需求:需要匹配deptList和deleteDept这2个方法,它们名称上没有相同的地方,参数列表也不同,一个有返回值,
|
||||||
一个没返回值,那怎么用一个切入点表达式表示呢??使用逻辑运算符||即可*/
|
一个没返回值,那怎么用一个切入点表达式表示呢??使用逻辑运算符||即可*/
|
||||||
@Pointcut("execution(* com.inmind.service.DeptService.deptList())" +
|
/*@Pointcut("execution(* com.inmind.service.DeptService.deptList())" +
|
||||||
"||execution(* com.inmind.service.DeptService.deleteDept(Integer))")//此处表示所有方法
|
"||execution(* com.inmind.service.DeptService.deleteDept(Integer))")//此处表示所有方法
|
||||||
private void pt(){}
|
private void pt(){}*/
|
||||||
|
|
||||||
@Before("pt()")
|
@Before("@annotation(com.inmind.annotation.MyLog)")
|
||||||
public void before(){
|
public void before(){
|
||||||
log.info("MyAspect6 ... before ...");
|
log.info("MyAspect6 ... before ...");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.inmind.service.impl;
|
package com.inmind.service.impl;
|
||||||
|
|
||||||
|
import com.inmind.annotation.MyLog;
|
||||||
import com.inmind.mapper.DeptMapper;
|
import com.inmind.mapper.DeptMapper;
|
||||||
import com.inmind.pojo.Dept;
|
import com.inmind.pojo.Dept;
|
||||||
import com.inmind.service.DeptService;
|
import com.inmind.service.DeptService;
|
||||||
@@ -19,6 +20,7 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
|
|
||||||
//查询部门列表
|
//查询部门列表
|
||||||
@Override
|
@Override
|
||||||
|
@MyLog
|
||||||
public List<Dept> deptList() {
|
public List<Dept> deptList() {
|
||||||
//int i = 1/0;
|
//int i = 1/0;
|
||||||
//调用deptMapper获取部门列表数据
|
//调用deptMapper获取部门列表数据
|
||||||
@@ -29,6 +31,7 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
//根据id删除部门
|
//根据id删除部门
|
||||||
@Transactional(rollbackFor = Exception.class)//让当前方法,处于事务管理下(在方法调用前,执行start transaction)
|
@Transactional(rollbackFor = Exception.class)//让当前方法,处于事务管理下(在方法调用前,执行start transaction)
|
||||||
@Override
|
@Override
|
||||||
|
@MyLog
|
||||||
public void deleteDept(Integer id) throws Exception {
|
public void deleteDept(Integer id) throws Exception {
|
||||||
deptMapper.deleteDept(id);
|
deptMapper.deleteDept(id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user