May 14, 2021 JFinal manual
AOP in JFinal is divided into control layer AOP and business layer AOP, and business layer AOP is not strictly limited to the business layer because JFinal AOP can be applied anywhere else.
The trigger of the control layer interceptor simply initiates an action request. T he trigger of the business layer interceptor requires the target object to be enhanced using the enhance method before the target method can be called. The following is an example of the use of business-tier AOP:
// 定义需要使用AOP的业务层类
public class OrderService {
// 配置事务拦截器
@Before(Tx.class)
public void payment(int orderId, int userId) {
// service code here
}
}
// 定义控制器,控制器提供了enhance系列方法可对目标进行AOP增强
public class OrderController extends Controller {
public void payment() {
// 使用 enhance方法对业务层进行增强,使其具有AOP能力 OrderService service = enhance(OrderService.class);
// 调用payment方法时将会触发拦截器
service.payment(getParaToInt("orderId"), getParaToInt("userId"));
}
}
In the above code, OrderService is a business layer class where the Tx transaction interceptor is configured on top of the payment method, and OrderController is the controller, where orderSevice is enhanced with the enhancer method, and then the Tx interceptor is triggered by calling its payment method. In short, the business layer AOP is triggered by just one more call to the enhance method than the control layer, and Interceptor, Before, and Clear are used exactly the same way.