{"id":44442,"date":"2024-12-01T14:44:07","date_gmt":"2024-12-01T06:44:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/44442\/"},"modified":"2024-12-01T14:44:07","modified_gmt":"2024-12-01T06:44:07","slug":"transactional%e6%b3%a8%e8%a7%a3%e6%a0%87%e6%b3%a8%e6%96%b9%e6%b3%95%e7%9a%84%e4%ba%8b%e5%8a%a1%e6%8f%90%e4%ba%a4%e6%97%b6%e9%97%b4%e7%82%b9%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/44442\/","title":{"rendered":"@Transactional\u6ce8\u89e3\u6807\u6ce8\u65b9\u6cd5\u7684\u4e8b\u52a1\u63d0\u4ea4\u65f6\u95f4\u70b9\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>@Transactional\u6ce8\u89e3\u6807\u6ce8\u65b9\u6cd5\u7684\u4e8b\u52a1\u63d0\u4ea4\u65f6\u95f4\u70b9\u662f\u4ec0\u4e48\uff1f<\/h1>\n<p>\u77e5\u8bc6\u70b9\u638c\u63e1\u4e86\uff0c\u8fd8\u9700\u8981\u4e0d\u65ad\u7ec3\u4e60\u624d\u80fd\u719f\u7ec3\u8fd0\u7528\u3002\u4e0b\u9762\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u4e2a\u6570\u636e\u5e93\u5f00\u53d1\u5b9e\u6218\uff0c\u624b\u628a\u624b\u6559\u5927\u5bb6\u5b66\u4e60\u300a@Transactional\u6ce8\u89e3\u6807\u6ce8\u65b9\u6cd5\u7684\u4e8b\u52a1\u63d0\u4ea4\u65f6\u95f4\u70b9\u662f\u4ec0\u4e48\uff1f\u300b\uff0c\u5728\u5b9e\u73b0\u529f\u80fd\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u5e26\u5927\u5bb6\u91cd\u65b0\u6e29\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6e29\u6545\u800c\u77e5\u65b0\uff0c\u56de\u5934\u770b\u770b\u8bf4\u4e0d\u5b9a\u53c8\u6709\u4e0d\u4e00\u6837\u7684\u611f\u609f\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729853489671b78318ee98.jpg\" class=\"aligncenter\" title=\"@Transactional\u6ce8\u89e3\u6807\u6ce8\u65b9\u6cd5\u7684\u4e8b\u52a1\u63d0\u4ea4\u65f6\u95f4\u70b9\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" alt=\"@Transactional\u6ce8\u89e3\u6807\u6ce8\u65b9\u6cd5\u7684\u4e8b\u52a1\u63d0\u4ea4\u65f6\u95f4\u70b9\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>spring\u4e2d@transactional\u6ce8\u89e3\u7684\u4e8b\u52a1\u63d0\u4ea4\u65f6\u95f4\u70b9<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528@transactional\u6ce8\u89e3\u6807\u6ce8\u7684\u65b9\u6cd5\u6267\u884c\u524d\u540e\uff0c\u4e8b\u52a1\u63d0\u4ea4\u7684\u65f6\u95f4\u70b9\u662f\u4f55\u65f6\uff1f<\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong><\/p>\n<p>spring\u4e2d\u4f7f\u7528@transactional\u6ce8\u89e3\u6807\u6ce8\u7684\u65b9\u6cd5\uff0c\u4e8b\u52a1\u7684\u63d0\u4ea4\u65f6\u95f4\u70b9\u662f\u5728\u65b9\u6cd5\u6267\u884c\u7ed3\u675f\u540e\u3002<\/p>\n<p>spring\u91c7\u7528\u52a8\u6001\u4ee3\u7406\u7684\u65b9\u5f0f\u5bf9\u52a0\u4e86@transactional\u6ce8\u89e3\u7684\u65b9\u6cd5\u8fdb\u884c\u589e\u5f3a\uff0c\u5728\u65b9\u6cd5\u6267\u884c\u524d\u6dfb\u52a0\u4e8b\u52a1\uff0c\u5e76\u5728\u65b9\u6cd5\u6267\u884c\u5b8c\u6210\u540e\u63d0\u4ea4\u4e8b\u52a1\u3002\u56e0\u6b64\uff0c\u4e8b\u52a1\u7684\u63d0\u4ea4\u65f6\u95f4\u70b9\u786e\u5b9e\u662f\u5728\u65b9\u6cd5\u7ed3\u675f\u65f6\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5:<\/strong><\/p>\n<p>\u5982\u679c\u9700\u8981\u5728\u65b9\u6cd5\u6267\u884c\u524d\u5f00\u542f\u4e8b\u52a1\uff0c\u53ef\u4ee5\u5728\u65b9\u6cd5\u4e2d\u624b\u52a8\u83b7\u53d6\u4e8b\u52a1\uff0c\u7136\u540e\u518d\u8c03\u7528\u5e26@transactional\u6ce8\u89e3\u7684\u65b9\u6cd5\u3002<\/p>\n<pre>lock();\ntransactionTemplate.execute(new TransactionCallbackWithoutResult() {\n    @Override\n    protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {\n        method();\n    }\n});\nunlock();<\/pre>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6570\u636e\u5e93\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n<p> \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1aphp \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664 <\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>@Transactional\u6ce8\u89e3\u6807\u6ce8\u65b9\u6cd5\u7684\u4e8b\u52a1\u63d0\u4ea4\u65f6\u95f4\u70b9\u662f\u4ec0\u4e48\uff1f \u77e5\u8bc6\u70b9\u638c\u63e1\u4e86\uff0c\u8fd8\u9700\u8981\u4e0d\u65ad\u7ec3\u4e60\u624d\u80fd\u719f\u7ec3\u8fd0\u7528\u3002\u4e0b\u9762\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u4e2a\u6570\u636e\u5e93\u5f00\u53d1\u5b9e\u6218\uff0c\u624b\u628a\u624b\u6559\u5927\u5bb6\u5b66\u4e60\u300a@Transactional\u6ce8\u89e3\u6807\u6ce8\u65b9\u6cd5\u7684\u4e8b\u52a1\u63d0\u4ea4\u65f6\u95f4\u70b9\u662f\u4ec0\u4e48\uff1f\u300b\uff0c\u5728\u5b9e\u73b0\u529f\u80fd\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u5e26\u5927\u5bb6\u91cd\u65b0\u6e29\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6e29\u6545\u800c\u77e5\u65b0\uff0c\u56de\u5934\u770b\u770b\u8bf4\u4e0d\u5b9a\u53c8\u6709\u4e0d\u4e00\u6837\u7684\u611f\u609f\uff01 spring\u4e2d@transactional\u6ce8\u89e3\u7684\u4e8b\u52a1\u63d0\u4ea4\u65f6\u95f4\u70b9 \u95ee\u9898\uff1a \u4f7f\u7528@transactional\u6ce8\u89e3\u6807\u6ce8\u7684\u65b9\u6cd5\u6267\u884c\u524d\u540e\uff0c\u4e8b\u52a1\u63d0\u4ea4\u7684\u65f6\u95f4\u70b9\u662f\u4f55\u65f6\uff1f \u56de\u7b54\uff1a spring\u4e2d\u4f7f\u7528@transactional\u6ce8\u89e3\u6807\u6ce8\u7684\u65b9\u6cd5\uff0c\u4e8b\u52a1\u7684\u63d0\u4ea4\u65f6\u95f4\u70b9\u662f\u5728\u65b9\u6cd5\u6267\u884c\u7ed3\u675f\u540e\u3002 spring\u91c7\u7528\u52a8\u6001\u4ee3\u7406\u7684\u65b9\u5f0f\u5bf9\u52a0\u4e86@transactional\u6ce8\u89e3\u7684\u65b9\u6cd5\u8fdb\u884c\u589e\u5f3a\uff0c\u5728\u65b9\u6cd5\u6267\u884c\u524d\u6dfb\u52a0\u4e8b\u52a1\uff0c\u5e76\u5728\u65b9\u6cd5\u6267\u884c\u5b8c\u6210\u540e\u63d0\u4ea4\u4e8b\u52a1\u3002\u56e0\u6b64\uff0c\u4e8b\u52a1\u7684\u63d0\u4ea4\u65f6\u95f4\u70b9\u786e\u5b9e\u662f\u5728\u65b9\u6cd5\u7ed3\u675f\u65f6\u3002 \u89e3\u51b3\u65b9\u6cd5: \u5982\u679c\u9700\u8981\u5728\u65b9\u6cd5\u6267\u884c\u524d\u5f00\u542f\u4e8b\u52a1\uff0c\u53ef\u4ee5\u5728\u65b9\u6cd5\u4e2d\u624b\u52a8\u83b7\u53d6\u4e8b\u52a1\uff0c\u7136\u540e\u518d\u8c03\u7528\u5e26@transactional\u6ce8\u89e3\u7684\u65b9\u6cd5\u3002 lock(); transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) { method(); } }); unlock(); \u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6570\u636e\u5e93\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~ \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1aphp \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664<\/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-44442","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/44442","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=44442"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/44442\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=44442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=44442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=44442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}