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 ""; }

     

  • 相关阅读:
    再谈树形dp
    洛谷 P3627 [APIO2009]抢掠计划
    树状数组
    树形dp 入门
    洛谷P2014 选课
    洛谷P2015 二叉苹果树
    9 vue.js 被观察数组的变异方法
    8 vue的v-model指令学习
    7vue-事件修饰符
    6.vue事件绑定-click
  • 原文地址:https://www.cnblogs.com/wangnanhui/p/10334027.html
Copyright © 2011-2022 走看看