欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Nano Framework之切面编程

程序员文章站 2022-07-12 20:10:52
...
1、编写AOP
1.1、AOP注解
  • @Before
  • @After
  • @BeforeAndAfter


1.2、在src/main/java/org.nanoframework.examples.first.webapp.aop下添加
public class ExamplesAOP {
    private Logger LOG = LoggerFactory.getLogger(ExamplesAOP.class);

    public void before(MethodInvocation invocation) {
        if(LOG.isDebugEnabled()) {
            String params = StringUtils.join(invocation.getMethod().getParameters(), ", ");
            String args = StringUtils.join(invocation.getArguments(), ", ");
            LOG.debug("Before invoke method: " + invocation.getThis().getClass().getName() + "." + invocation.getMethod().getName() + "("+ (params == null ? "" : params) +"):: [" + (args == null ? "" : args) + "]");
        }
    }
}


1.3、修改MybatisExampleComponentImpl
@Before(classType = ExamplesAOP.class, methodName = "before")
public Object findAll() {
...
}


1.4、注意事项
  • 需要进行AOP的方法必须是public的
  • AOP的实现必须是public


2、至此,AOP的服务开发完成

上一篇: spring整合ORM框架

下一篇: Java Mybatis