{"id":7782,"date":"2024-11-14T13:51:39","date_gmt":"2024-11-14T05:51:39","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7782\/"},"modified":"2024-11-14T13:51:39","modified_gmt":"2024-11-14T05:51:39","slug":"mybatis-%e6%89%b9%e9%87%8f%e6%8f%92%e5%85%a5%e6%97%b6%e6%8b%a6%e6%88%aa%e5%99%a8%e5%a4%b1%e6%95%88%e7%9a%84%e5%8e%9f%e5%9b%a0%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7782\/","title":{"rendered":"MyBatis \u6279\u91cf\u63d2\u5165\u65f6\u62e6\u622a\u5668\u5931\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173123137634267.jpg\" class=\"aligncenter\" title=\"MyBatis \u6279\u91cf\u63d2\u5165\u65f6\u62e6\u622a\u5668\u5931\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" alt=\"MyBatis \u6279\u91cf\u63d2\u5165\u65f6\u62e6\u622a\u5668\u5931\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>mybatis\u6279\u91cf\u63d2\u5165\u65f6\u62e6\u622a\u5668\u5931\u6548\u7684\u539f\u56e0<\/strong><\/p>\n<p>\u4f7f\u7528mybatis\u65f6\uff0c\u6279\u91cf\u63d2\u5165\u6570\u636e\u53ef\u80fd\u4f1a\u5bfc\u81f4\u62e6\u622a\u5668\u5931\u6548\u3002\u8fd9\u662f\u56e0\u4e3a\u5728\u6267\u884c\u6279\u91cf\u63d2\u5165\u65f6\uff0cmybatis\u4f1a\u4f7f\u7528statementhandler\u6267\u884c\u66f4\u65b0\uff0c\u800c\u4e0d\u662fexecutor\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u62e6\u622a\u5668\u53ea\u62e6\u622aexecutor\u4e0a\u7684update\u65b9\u6cd5\uff0c\u56e0\u6b64\u4e0d\u4f1a\u88ab\u89e6\u53d1\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u9700\u8981\u5728@intercepts\u6ce8\u89e3\u4e2d\u6dfb\u52a0statementhandler.update\u65b9\u6cd5\u7684\u7b7e\u540d\uff0c\u4ee5\u786e\u4fdd\u62e6\u622a\u5668\u53ef\u4ee5\u62e6\u622a\u6279\u91cf\u63d2\u5165\u3002\u4fee\u6539\u540e\u7684\u62e6\u622a\u5668\u5982\u4e0b\uff1a<\/p>\n<pre>@Component\n@Intercepts({\n        @Signature(type = Executor.class,method = \"update\",args = {MappedStatement.class, Object.class}),\n        @Signature(type = StatementHandler.class,method = \"update\",args = {Statement.class})\n})\npublic class MyBatisAutoFillPlugin implements Interceptor {\n    \/\/ some code...\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMyBatis \u6279\u91cf\u63d2\u5165\u65f6\u62e6\u622a\u5668\u5931\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>mybatis\u6279\u91cf\u63d2\u5165\u65f6\u62e6\u622a\u5668\u5931\u6548\u7684\u539f\u56e0 \u4f7f\u7528mybatis\u65f6\uff0c\u6279\u91cf\u63d2\u5165\u6570\u636e\u53ef\u80fd\u4f1a\u5bfc\u81f4\u62e6\u622a\u5668\u5931\u6548\u3002\u8fd9\u662f\u56e0\u4e3a\u5728\u6267\u884c\u6279\u91cf\u63d2\u5165\u65f6\uff0cmybatis\u4f1a\u4f7f\u7528statementhandler\u6267\u884c\u66f4\u65b0\uff0c\u800c\u4e0d\u662fexecutor\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u62e6\u622a\u5668\u53ea\u62e6\u622aexecutor\u4e0a\u7684update\u65b9\u6cd5\uff0c\u56e0\u6b64\u4e0d\u4f1a\u88ab\u89e6\u53d1\u3002 \u89e3\u51b3\u65b9\u6cd5 \u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u9700\u8981\u5728@intercepts\u6ce8\u89e3\u4e2d\u6dfb\u52a0statementhandler.update\u65b9\u6cd5\u7684\u7b7e\u540d\uff0c\u4ee5\u786e\u4fdd\u62e6\u622a\u5668\u53ef\u4ee5\u62e6\u622a\u6279\u91cf\u63d2\u5165\u3002\u4fee\u6539\u540e\u7684\u62e6\u622a\u5668\u5982\u4e0b\uff1a @Component @Intercepts({ @Signature(type = Executor.class,method = &#8220;update&#8221;,args = {MappedStatement.class, Object.class}), @Signature(type = StatementHandler.class,method = &#8220;update&#8221;,args = {Statement.class}) }) public class MyBatisAutoFillPlugin implements Interceptor { \/\/ some code&#8230; } \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0a\u5c31\u662fMyBatis \u6279\u91cf\u63d2\u5165\u65f6\u62e6\u622a\u5668\u5931\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7782","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7782","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=7782"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7782\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}