密码:
网络营销 it新闻 军事新闻 社会新闻 it技术 网站优化 游戏资讯 公司资讯
JAVA-Spring注解实现AOP权限拦截,如何取得方法上自定义Annotation的值呢?
发布日期:2018-05-03 阅读数:1485 来源:互联网 由金功呈网站建设公司整理 【关闭】



import java.lang.annotation.Retention;

import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@Retention(RetentionPolicy.RUNTIME)
@interface GetView {
String Method();
String Value();
}
public class Temp {
@GetView(Method = "aa", Value = "bb")
public void test() {
System.out.println("In test method.");
}
public static void main(String[] args) throws ClassNotFoundException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException {
Temp temp = new Temp();
Method method = temp.getClass().getMethod("test");
System.out.println(method.isAnnotationPresent(GetView.class));
method.invoke(temp);
GetView view = method.getAnnotation(GetView.class);
System.out.println(view.Method());
System.out.println(view.Value());
}
}

广州金功呈网站建设网微信二维码
  • 深圳市一键一家网络科技有限公司官方网址:http://www.songhu9.com.cn
  • QQ:316675593,电话号码:19807655856
  • 业务范围:公司网站建设、管理软件研发、软件网站二次开发、400电话、电商平台研发、公众号研发!
  • 免责申明:本站内容均来源于网络,版权归原创所有,如有任何版权方面的问题,请与我们联系处理!