{"id":37845,"date":"2023-12-11T14:42:41","date_gmt":"2023-12-11T06:42:41","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=37845"},"modified":"2023-12-11T14:42:41","modified_gmt":"2023-12-11T06:42:41","slug":"mybatis-%e5%a6%82%e4%bd%95%e7%bc%96%e5%86%99%e4%b8%80%e4%b8%aa%e8%87%aa%e5%ae%9a%e4%b9%89%e6%8f%92%e4%bb%b6%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/11\/mybatis-%e5%a6%82%e4%bd%95%e7%bc%96%e5%86%99%e4%b8%80%e4%b8%aa%e8%87%aa%e5%ae%9a%e4%b9%89%e6%8f%92%e4%bb%b6%ef%bc%9f\/","title":{"rendered":"MyBatis \u5982\u4f55\u7f16\u5199\u4e00\u4e2a\u81ea\u5b9a\u4e49\u63d2\u4ef6\uff1f"},"content":{"rendered":"<p>&#8220;`&#8221;                    \u81ea\u5b9a\u4e49\u63d2\u4ef6\u5b9e\u73b0\u539f\u7406\uff1a<\/p>\n<p>MyBatis \u81ea\u5b9a\u4e49\u63d2\u4ef6\u9488\u5bf9 MyBatis \u56db\u5927\u5bf9\u8c61\uff08Executor\u3001StatementHandler\u3001ParameterHandler\u3001ResultSetHandler\uff09\u8fdb\u884c\u62e6\u622a\uff1aExecutor\uff1a\u62e6\u622a\u5185\u90e8\u6267\u884c\u5668\uff0c\u5b83\u8d1f\u8d23\u8c03\u7528 StatementHandler \u64cd\u4f5c\u6570\u636e\u5e93\uff0c\u5e76\u628a\u7ed3\u679c\u96c6\u901a\u8fc7 ResultSetHandler \u8fdb\u884c\u81ea\u52a8\u6620\u5c04\uff0c\u53e6\u5916\u5b83\u8fd8\u5904\u7406\u4e86\u4e8c\u7ea7\u7f13\u5b58\u7684\u64cd\u4f5c\uff1bStatementHandler\uff1a\u62e6\u622a SQL \u8bed\u6cd5\u6784\u5efa\u7684\u5904\u7406\uff0c\u5b83\u662f MyBatis \u76f4\u63a5\u548c\u6570\u636e\u5e93\u6267\u884c SQL \u811a\u672c\u7684\u5bf9\u8c61\uff0c\u53e6\u5916\u5b83\u4e5f\u5b9e\u73b0\u4e86 MyBatis \u7684\u4e00\u7ea7\u7f13\u5b58\uff1bParameterHandler\uff1a\u62e6\u622a\u53c2\u6570\u7684\u5904\u7406\uff1bResultSetHandler\uff1a\u62e6\u622a\u7ed3\u679c\u96c6\u7684\u5904\u7406\u3002\u81ea\u5b9a\u4e49\u63d2\u4ef6\u5b9e\u73b0\u5173\u952e\uff1aMyBatis \u63d2\u4ef6\u8981\u5b9e\u73b0 Interceptor \u63a5\u53e3\uff0c\u63a5\u53e3\u5305\u542b\u7684\u65b9\u6cd5\uff0c\u5982\u4e0b\uff1a<\/p>\n<p>&lt;pre&gt;&lt;code&gt;public interface Interceptor { Object intercept(Invocation invocation) throws Throwable; Object plugin(Object target); void setProperties(Properties properties);}&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>setProperties \u65b9\u6cd5\u662f\u5728 MyBatis \u8fdb\u884c\u914d\u7f6e\u63d2\u4ef6\u7684\u65f6\u5019\u53ef\u4ee5\u914d\u7f6e\u81ea\u5b9a\u4e49\u76f8\u5173\u5c5e\u6027\uff0c\u5373\uff1a\u63a5\u53e3\u5b9e\u73b0\u5bf9\u8c61\u7684\u53c2\u6570\u914d\u7f6e\uff1bplugin \u65b9\u6cd5\u662f\u63d2\u4ef6\u7528\u4e8e\u5c01\u88c5\u76ee\u6807\u5bf9\u8c61\u7684\uff0c\u901a\u8fc7\u8be5\u65b9\u6cd5\u6211\u4eec\u53ef\u4ee5\u8fd4\u56de\u76ee\u6807\u5bf9\u8c61\u672c\u8eab\uff0c\u4e5f\u53ef\u4ee5\u8fd4\u56de\u4e00\u4e2a\u5b83\u7684\u4ee3\u7406\uff0c\u53ef\u4ee5\u51b3\u5b9a\u662f\u5426\u8981\u8fdb\u884c\u62e6\u622a\u8fdb\u800c\u51b3\u5b9a\u8981\u8fd4\u56de\u4e00\u4e2a\u4ec0\u4e48\u6837\u7684\u76ee\u6807\u5bf9\u8c61\uff0c\u5b98\u65b9\u63d0\u4f9b\u4e86\u793a\u4f8b\uff1areturn Plugin. wrap(target, this)\uff1bintercept \u65b9\u6cd5\u5c31\u662f\u8981\u8fdb\u884c\u62e6\u622a\u7684\u65f6\u5019\u8981\u6267\u884c\u7684\u65b9\u6cd5\u3002\u81ea\u5b9a\u4e49\u63d2\u4ef6\u5b9e\u73b0\u793a\u4f8b\uff1a\u5b98\u65b9\u63d2\u4ef6\u5b9e\u73b0\uff1a<\/p>\n<p>&lt;pre&gt;&lt;code&gt;@Intercepts({@Signature(type = Executor. class, method = &quot;&quot;query&quot;&quot;,args = {MappedStatement. class, Object. class, RowBounds. class, ResultHandler. class})})public class TestInterceptor implements Interceptor {public Object intercept(Invocation invocation) throws Throwable {Object target = invocation. getTarget(); \/\/\u88ab\u4ee3\u7406\u5bf9\u8c61Method method = invocation. getMethod(); \/\/\u4ee3\u7406\u65b9\u6cd5Object[] args = invocation. getArgs(); \/\/\u65b9\u6cd5\u53c2\u6570\/\/ do something . . . . . . \u65b9\u6cd5\u62e6\u622a\u524d\u6267\u884c\u4ee3\u7801\u5757Object result = invocation. proceed();\/\/ do something . . . . . . . \u65b9\u6cd5\u62e6\u622a\u540e\u6267\u884c\u4ee3\u7801\u5757return result;}public Object plugin(Object target) {return Plugin. wrap(target, this);}}&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>\u00a0<\/p>\n<p>&lt;pre&gt;&lt;code&gt;            &quot;&#8220;`<br \/>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`&#8221; \u81ea\u5b9a\u4e49\u63d2\u4ef6\u5b9e\u73b0\u539f\u7406\uff1a MyBatis \u81ea\u5b9a\u4e49\u63d2\u4ef6\u9488\u5bf9 MyBatis \u56db\u5927\u5bf9\u8c61 [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-37845","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/37845","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=37845"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/37845\/revisions"}],"predecessor-version":[{"id":37846,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/37845\/revisions\/37846"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=37845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=37845"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=37845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}