Duang、Enhancer
Duang and Enhancer are used to enhance the target so that it has AOP capabilities. The following is a code example:
public class TestMain{ public void main(String[] args) { // 使用Duang.duang方法在任何地方对目标进行增强 OrderService service = Duang.duang(OrderService.class); // 调用payment方法时将会触发拦截器 service.payment(…); // 使用Enhancer.enhance方法在任何地方对目标进行增强 OrderService service = Enhancer.enhance(OrderService.class); } }
Duang.duang(), Enhancer.enhance() and Controller.enhance() methods are exactly the same in function. In addition to supporting class enhancement, they also support object enhancement, such as The usage of duang(new OrderService()) with objects as parameters is essentially the same function, so I won’t go into details here.
Using the Duang and Enhancer classes can enhance any target anywhere, so JFinal's AOP can be applied to non-web projects. You only need to introduce the jfinal.jar package, and then use Enhancer.enhance() or Duang.duang () to quickly use JFinal’s AOP function.