public class AddressBookAccessToken implements Interceptor { @Inject WxTokenService wxTokenService; @Override public void intercept(Invocation invocation) { Controller controller = invocation.getController(); Result result = wxTokenService.checkAccessToken(WxTokenService.ADDRESS_BOOK); if (result.errcode == 0) { invocation.invoke(); } else { controller.renderJson(result); } } } 如上:通过 Result result = wxTokenService.checkAccessToken(WxTokenService.ADDRESS_BOOK); 可以拿到一个访问令牌 result.access_token。 @Before(AddressBookAccessToken.class) public void test() { String access_token = getPara("access_token"); //... }
项目:JFinal
添加 @Para 参数也可以做到:
Para para = inv.getMethod().getAnnotation(Para.class);
if (para != null) {
Object value = para.value();
}