扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

MyBatis鐨凙OP鎬庝箞搴旂敤

扬州沐宇科技
2024-05-08 12:51:56
mybatis

MyBatis鐨凙OP鏄€氳繃鎷︽埅鍣ㄥ疄鐜扮殑锛屽彲浠ュ湪MyBatis鐨勯厤缃枃浠朵腑閰嶇疆鎷︽埅鍣紝鐒跺悗鍦ㄩ渶瑕佽繘琛孉OP鎿嶄綔鐨勫湴鏂逛娇鐢ㄣ€?/p>

  1. 鍒涘缓涓€涓疄鐜癐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>
    }
}
  1. 鍦∕yBatis鐨勯厤缃枃浠朵腑閰嶇疆鎷︽埅鍣ㄣ€?/li>
<configuration>
    <plugins>
        <plugin interceptor="com.example.MyInterceptor">
            <!-- 鍙互閰嶇疆涓€浜涘睘鎬?-->
        </plugin>
    </plugins>
</configuration>
  1. 鍦ㄩ渶瑕佽繘琛孉OP鎿嶄綔鐨勫湴鏂逛娇鐢ㄦ嫤鎴櫒銆?/li>
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
SqlSession sqlSession = sqlSessionFactory.openSession();

MyMapper mapper = sqlSession.getMapper(MyMapper.class);

閫氳繃浠ヤ笂姝ラ锛屽氨鍙互鍦∕yBatis涓娇鐢ˋOP杩涜涓€浜涜嚜瀹氫箟鐨勬搷浣滐紝姣斿鏃ュ織璁板綍銆佹€ц兘鐩戞帶绛夈€?/p>

扫码添加客服微信