🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
@Component @Aspect @EnableAspectJAutoProxy public class CacheAspect { @Autowired private JedisPool jedisPool; private static final String ALL\_MENU\_LABEL = "alll-menu-data"; @Pointcut("execution(\* com.sxt.service.impl.MenuServiceImpl.queryAllMenuForList())") public void menuQueryPc() { } @Around(value="menuQueryPc()") public Object cache(ProceedingJoinPoint point) { Jedis jedis = jedisPool.getResource(); if(jedis.exists(ALL\_MENU\_LABEL)) { String menuJson = jedis.get(ALL\_MENU\_LABEL); List<Menu> menu = JSON.parseArray(menuJson, Menu.class); return menu ; } Object result = null ; try { System.out.println("执行真实方法的调用"); result = point.proceed(point.getArgs()); // 在此实现了真实方法的调用 jedis.set(ALL\_MENU\_LABEL,JSON.toJSONString(result)); } catch (Throwable e) { e.printStackTrace(); } return result; } }