MyBatis鐨凙OP鎬庝箞搴旂敤
MyBatis鐨凙OP鏄€氳繃鎷︽埅鍣ㄥ疄鐜扮殑锛屽彲浠ュ湪MyBatis鐨勯厤缃枃浠朵腑閰嶇疆鎷︽埅鍣紝鐒跺悗鍦ㄩ渶瑕佽繘琛孉OP鎿嶄綔鐨勫湴鏂逛娇鐢ㄣ€?/p>
- 鍒涘缓涓€涓疄鐜癐nterceptor鎺ュ彛鐨勭被锛岀紪鍐欐嫤鎴€昏緫銆?/li>
public class MyInterceptor implements Interceptor {
@Override
public Object intercept(Invocation invocation) throws Throwable {
// 鍦ㄦ澶勭紪鍐欐嫤鎴€昏緫
return invocation.proceed();
}
@Override
public Object plugin(Object target) {
return Plugin.wrap(target, this);
}
@Override
public void setProperties(Properties properties) {
// 璁剧疆灞炴€?/span>
}
}
- 鍦∕yBatis鐨勯厤缃枃浠朵腑閰嶇疆鎷︽埅鍣ㄣ€?/li>
<configuration>
<plugins>
<plugin interceptor="com.example.MyInterceptor">
<!-- 鍙互閰嶇疆涓€浜涘睘鎬?-->
</plugin>
</plugins>
</configuration>
- 鍦ㄩ渶瑕佽繘琛孉OP鎿嶄綔鐨勫湴鏂逛娇鐢ㄦ嫤鎴櫒銆?/li>
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
SqlSession sqlSession = sqlSessionFactory.openSession();
MyMapper mapper = sqlSession.getMapper(MyMapper.class);
閫氳繃浠ヤ笂姝ラ锛屽氨鍙互鍦∕yBatis涓娇鐢ˋOP杩涜涓€浜涜嚜瀹氫箟鐨勬搷浣滐紝姣斿鏃ュ織璁板綍銆佹€ц兘鐩戞帶绛夈€?/p>
相关问答