Aspect 切面
This commit is contained in:
parent
d248384b4f
commit
6d767daf9e
|
|
@ -0,0 +1,22 @@
|
|||
package com.ruoyi.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* description: new java files...TODO
|
||||
* @version v1.0
|
||||
* @author w
|
||||
* @date 2021年5月10日下午5:29:30
|
||||
**/
|
||||
@Documented
|
||||
@Inherited
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface AspectTest {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package com.ruoyi.aspect;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* description: new java files...TODO
|
||||
* @version v1.0
|
||||
* @author w
|
||||
* @date 2021年5月10日下午5:29:43
|
||||
**/
|
||||
@Component
|
||||
@Aspect
|
||||
public class Aspects {
|
||||
|
||||
/**
|
||||
* description: 配置切点
|
||||
* @return void
|
||||
* @version v1.0
|
||||
* @author w
|
||||
* @date 2021年5月10日 下午4:13:32
|
||||
*/
|
||||
@Pointcut(value = "@annotation(com.ruoyi.annotation.AspectTest)")
|
||||
public void pointCut() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* description: 配置环绕
|
||||
* @param point
|
||||
* @throws Throwable
|
||||
* @return Object
|
||||
* @version v1.0
|
||||
* @author w
|
||||
* @date 2021年5月10日 下午4:25:51
|
||||
*/
|
||||
@Around("pointCut()")
|
||||
public void around(ProceedingJoinPoint point) throws Throwable {
|
||||
System.out.println("========== 切面到l ======");
|
||||
point.proceed();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.ruoyi.web.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.ruoyi.annotation.AspectTest;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
|
||||
/**
|
||||
* description: 测试 @AspectTest
|
||||
* @version v1.0
|
||||
* @author w
|
||||
* @date 2021年5月10日下午5:32:01
|
||||
**/
|
||||
@RestController
|
||||
public class AspectController {
|
||||
|
||||
@AspectTest
|
||||
@RequestMapping(value = "/AspectController")
|
||||
@ResponseBody
|
||||
public AjaxResult te() {
|
||||
System.out.println("==========");
|
||||
return AjaxResult.success("AspectController");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue