直接上代碼:
mybatis配置中 添加
有的SqlSessionFactoryFactoryBean類中沒有plugins屬性
(private Interceptor[] plugins;生成setter方法 ),
定義屬性后將插件添加到Configuration conf = sqlSessionFactory.getConfiguration();如下
if (null!=this.plugins) {
for (Interceptor plugin : this.plugins) {
conf.addInterceptor(plugin);
if (this.logger.isDebugEnabled()) {
this.logger.debug("Registered plugin: '" + plugin + "'");
}
}
}
關(guān)于攔截類 PageInterceptor
如果要保存sql以及sql對(duì)應(yīng)的值問題:
sql數(shù)據(jù)問題:sql中有特殊符號(hào)是無法保存到數(shù)據(jù)庫中的,通過url編碼后保存到數(shù)據(jù)庫,如果要查看時(shí)再反編碼即可
sql對(duì)應(yīng)值的問題:1.對(duì)象轉(zhuǎn)為json數(shù)據(jù),2,直接獲取
public static String getStringParame(Object obj){
JSONObject json = JSONObject.fromObject(obj);//將java對(duì)象轉(zhuǎn)換為json對(duì)象
String str = json.toString();//將json對(duì)象轉(zhuǎn)換為字符串
//不是json直接返回字符串
if(str.equals("") || str.equals("{}")){
str = obj.toString();
}
return str;
}