Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

4.6 Duang、Enhancer


May 14, 2021 JFinal manual



Duang, Enhancr is used to enhance the target to give it the ability to have AOP. Here's an example of the code:

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 () are functionally identical, and in addition to supporting class enhancements, they also support object enhancements, such as the object-based use of duang (new OrderService(), which is essentially the same and will not be repeated here.


With the Duang, Enhancer classes, you can enhance any target anywhere, so JFinal's AOP can be applied to non-web projects by simply introducing a jfinal.jar package and then using Enhancer.enhance() or Duang.duang() to use JFinal's AOP features very quickly.