调用方法时如何触发我的自定义注释? [英] how can i trigger my custom annotation when method called?

查看:31
本文介绍了调用方法时如何触发我的自定义注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为 Web 编写自己的安全模块库,但我无法解决某些问题.例子;我有一个班级和一个方法.方法有我的自定义注解.

I want to write my own Secure module library for web but i not solution somethings. Example; I have a class and have a method. Method have my custom annotation.

class example{
  @Admin
  public void go(){
    syso("working");
  }
 }

当这个方法调用时,我如何触发我的注释.

When This method called , how can i trigger my annotation.

(例如;Hibernate Validators.我们在方法上编写了hibernate注解,它只对调用的方法起作用)

(Example; Hibernate Validators. We write hibernate annotation on method , it working only method called)

顺便说一下,我的英语不好:)

by the way my english is bad :)

推荐答案

注解不是触发"的……您必须编写代码来查找它们的存在并采取行动.

Annotations are not "triggered"... you have to write code that looks for their presence and takes action.

代码"可以在运行时执行,但更常见的是在编译时使用Annotation Processing Tool 改变源注入额外,通常 横切,适合注释的代码.

The "code" can either be executed at runtime, but is more commonly executed at compile time using the Annotation Processing Tool to alter the source to inject extra, typically cross-cutting, code appropriate for the annotation.

这篇关于调用方法时如何触发我的自定义注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆