自定义了一个拦截器:
@IocBean
public class ActionInterceptor implements MethodInterceptor {
@Override
public void filter(InterceptorChain chain) throws Throwable {
// TODO Auto-generated method stub
String ActionName = chain.getCallingObj().getClass().getName();
int loc = ActionName.indexOf("$");//首先获取字符的位置
ActionName = ActionName.substring(0,loc);//再对字符串进行截取,获得想要得到的字符串
String ActionMethodName = chain.getCallingMethod().getName();
Date beforeDate = new Date();
System.out.println("===================================Action调用开始:【"+ActionName+"】=====方法:【"+ActionMethodName+"】=========================>");
chain.doChain();// 继续执行其他拦截器
Date afterDate = new Date();
System.out.println("===================================Action调用结束:【"+ActionName+"】=====方法:【"+ActionMethodName+"】==============耗时:"+(afterDate.getTime()-beforeDate.getTime())+"毫秒===========>");
}
}
能够其作用:
===================================Action调用开始:【com.shlx.blood.action.UserAction】=====方法:【login】=========================>
sunxu - 666
2017-07-24 10:05:39,970 com.shlx.blood.service.ComServices.ExcuteServices(ComServices.java:80) INFO - FunctionId : B06.04.11 params:{loginName=sunxu, loginPwd=666}
2017-07-24 10:05:39,976 com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:1057) DEBUG - skip not validate connection.
2017-07-24 10:05:39,995 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT * FROM SYSFUNCTION WHERE functionid=?
| 1 |
|-----------|
| B06.04.11 |
For example:> "SELECT * FROM SYSFUNCTION WHERE functionid='B06.04.11'"
2017-07-24 10:05:39,998 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'userService'<class com.shlx.blood.service.business.UserService>
2017-07-24 10:05:39,999 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT * FROM SYSUSER WHERE LOGINNAME=? AND password=?
| 1 | 2 |
|-------|-----|
| sunxu | 666 |
For example:> "SELECT * FROM SYSUSER WHERE LOGINNAME='sunxu' AND password='666'"
===================================Action调用结束:【com.shlx.blood.action.UserAction】=====方法:【login】==============耗时:31毫秒===========>
但必须要在每个action中的每个方法上面标注一条@Aop({"actionInterceptor"}) 吗?
例如:
@At("/login")
@Aop({"actionInterceptor"})
public Object login(@Param("loginName")String loginName,@Param("loginPwd")String loginPwd) {
... ...
}
有没有其他方法可以让多个ACTION的每个方法都用到这个拦截器?