/**
* created by towery on 2018/10/10.
*/@component
@aspect
public class cacheaop
@pointcut("@annotation(com.towery.project.annotation.cacheclear)")
public void cacheclear(){}
@around("pointcut()")
public object around(proceedingjoinpoint joinpoint) throws throwable
if (value instanceof map) } }
} else }}
}// 請求類名稱
string targetname = joinpoint.gettarget().getclass().getname();
// 請求方法
string methodname = joinpoint.getsignature().getname();
//redis中key格式:請求類名稱 + 請求方法 + 目標方法引數
logger.info("呼叫從快取中查詢的方法(search cache),cachekey=" + rediskey);
//獲取從redis中查詢到的物件
object objectfromredis;
try }}
object dataobj = cachemap.get("data");
return dataobj;
}logger.info("沒有從快取中查到資料(no data from cache)");
//前置 沒有查到,那麼查詢資料庫
object object = null;
object = joinpoint.proceed(args);
mapresultmap = new hashmap();
resultmap.put("data", object);
// 新增分頁資料
for(object arg : args)
break;}}
//後置:將資料庫中查詢的資料放到redis中
logger.info("把資料庫查詢的資料儲存到快取中(put data to cache)");
// redisutil.setdata4object2redis(rediskey, object);
redisutil.setdata4object2redis(rediskey, resultmap);
//將查詢到的資料返回
return object;
} catch (exception e)
}@after(value = "cacheclear() && @annotation(cacheclear)", argnames = "joinpoint, cacheclear")
public void methodafter(joinpoint joinpoint, cacheclear cacheclear) throws throwable
string cachekey = cacheclear.key();
if (stringutils.isnotblank(cachekey))
try catch (exception e)
}private string string2unicode(string string)
return unicode.tostring();
}}
輕量級重量級
輕量級重量級某種程度上是以啟動程式需要的資源來決定。比如,ejb啟動的時候,需要消耗大量的資源,記憶體,cpu等,所以是重量級。而spring則不,所以是輕量級框架。量級主要是看對容器的依賴性所決定的,依賴性越小,越輕量.ejb往往內部做了很多服務,網上的說法是買一得三 而且你不想要就不行!比方說我...
輕量級容器
什麼是輕量級容器?為什麼我們需要輕量級容器?什麼是輕量級容器 所謂容器 container 指應用 的執行框架。業務物件在容器裡執行,被容器管理。像ejb就是過去管理j2ee業務物件時最常用的容器。任何容器都應該包含如下服務 上面講的是容器核心模組應該提供的服務,但是容器還必須提供其它一些服務,增加...
輕量級框架
1.概述 輕量級框架一般由struts,spring組成,側重於減小開發的複雜度,相應的它的處理能力便有所減弱 如事務功能弱 不具備分布式處理能力 比較適用於開發中小型企業應用。2.定義 輕量級框架是相對於重量級框架的一種設計模式 輕量級框架不帶有侵略性api,對容器也沒有依賴性,易於進行配置,易於...