本文介绍了之前和方法后,执行code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在服务层我有一个类,看起来像:

In the service layer I have a classes that look something like:

class MyService {
    public doSomething() {
        TelnetSession session = new TelnetSession();
        session.open("username", "password");
        session.execute("blah");
        session.close();
    }
}

在很多课我必须声明和公开会议,然后在年底关闭它。我宁愿做注解的东西,但我有不知道从哪里开始。怎么其他人做这样的事情:

In many classes I have to declare and open session and then at the end close it. I'd rather do something with annotations but I've got no idea where to start. How do other people do something like this:

class MyService {
    @TelnetTransaction
    public doSomething() {
        session.execute("blah");
    }
}

凡与 @TelnetTransaction 注释的方法实例,打开并且通过在 TelnetSession 对象。

where a method annotated with @TelnetTransaction instantiates, opens and passes in the TelnetSession object.

谢谢,

詹姆斯

推荐答案

前后是面向方面的编程是。

Before and after is what aspect oriented programming is for.

春季处理与交易方面。提供的Spring AOP还是AspectJ看看。

Spring handles transactions with aspects. Give Spring AOP or AspectJ a look.

这篇关于之前和方法后,执行code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 22:42