zoukankan      html  css  js  c++  java
  • java 动态修改注解值

    注解部分
    @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.METHOD }) @Documented
    public @interface Cacheable { public enum KeyMode { CACHEKEY, BASIC, ALL; } public String prefix() default ""; public String key() default ""; public KeyMode keyMode() default KeyMode.BASIC; public int expire() default 1800; }
       修改注解内部值
    @Cacheable(keyMode = KeyMode.ALL) public Object cached(final ProceedingJoinPoint pjp) throws Throwable { Class<?> cls = CacheProxyBiz.class; Method method = cls.getMethod("cached", ProceedingJoinPoint.class); Cacheable cacheable = method.getAnnotation(Cacheable.class);//获取注解 System.out.println("修改前....."); System.out.println("模式" + cacheable.keyMode() + " 时长" + cacheable.expire()); InvocationHandler invocationHandler = Proxy.getInvocationHandler(cacheable); Field value = invocationHandler.getClass().getDeclaredField("memberValues"); value.setAccessible(true); Map<String, Object> memberValues = (Map<String, Object>) value.get(invocationHandler); memberValues.put("expire", 50); System.out.println("修改后....."); System.out.println("模式" + cacheable.keyMode() + " 时长" + cacheable.expire()); return ""; }

     

  • 相关阅读:
    ASP.NET常用的三十三种代码
    asp.net获取IP地址
    Inside Microsoft Sql Server 2005 TSQL Programming 学习笔记
    动态SQL与SQL注入(一)动态SQL
    (二)SQL 注入
    WCF 安全
    C# 运算符重载和 implicit关键字
    分页那回事
    thinking
    Moss css
  • 原文地址:https://www.cnblogs.com/wangnanhui/p/10334027.html
Copyright © 2011-2022 走看看