{"id":6782,"date":"2024-11-14T09:03:10","date_gmt":"2024-11-14T01:03:10","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6782\/"},"modified":"2024-11-14T09:03:10","modified_gmt":"2024-11-14T01:03:10","slug":"%e5%9c%a8%e4%bd%bf%e7%94%a8%e5%8f%af%e9%87%8d%e5%a4%8d%e8%af%bb%e9%9a%94%e7%a6%bb%e7%ba%a7%e5%88%ab%e4%b8%8b%ef%bc%8c%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8d%e4%bd%bf%e7%94%a8%e4%ba%8b%e5%8a%a1%e6%b3%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6782\/","title":{"rendered":"\u5728\u4f7f\u7528\u53ef\u91cd\u590d\u8bfb\u9694\u79bb\u7ea7\u522b\u4e0b\uff0c\u5982\u4f55\u907f\u514d\u4f7f\u7528\u4e8b\u52a1\u6ce8\u89e3 (@Transactional) \u5bfc\u81f4\u7684\u5546\u54c1\u8d85\u5356\u95ee\u9898\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/172992245050353.jpg\" class=\"aligncenter\" title=\"\u5728\u4f7f\u7528\u53ef\u91cd\u590d\u8bfb\u9694\u79bb\u7ea7\u522b\u4e0b\uff0c\u5982\u4f55\u907f\u514d\u4f7f\u7528\u4e8b\u52a1\u6ce8\u89e3 (@Transactional) \u5bfc\u81f4\u7684\u5546\u54c1\u8d85\u5356\u95ee\u9898\uff1f\u63d2\u56fe\" alt=\"\u5728\u4f7f\u7528\u53ef\u91cd\u590d\u8bfb\u9694\u79bb\u7ea7\u522b\u4e0b\uff0c\u5982\u4f55\u907f\u514d\u4f7f\u7528\u4e8b\u52a1\u6ce8\u89e3 (@Transactional) \u5bfc\u81f4\u7684\u5546\u54c1\u8d85\u5356\u95ee\u9898\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>spring\u4e2d\u7684@transactional\u6ce8\u89e3\uff1a\u4e8b\u52a1\u63d0\u4ea4\u65f6\u673a\u89e3\u6790<\/strong><\/p>\n<p>\u672c\u7bc7\u6587\u7ae0\u63a2\u8ba8\u4e2d@transactional\u6ce8\u89e3\u5728\u65b9\u6cd5\u6267\u884c\u524d\u540e\u4e8b\u52a1\u63d0\u4ea4\u7684\u65f6\u673a\u3002<\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u5728\u4f7f\u7528\u53ef\u91cd\u590d\u8bfb\u9694\u79bb\u7ea7\u522b\u7684\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u4e8b\u52a1\u7684\u5f00\u542f\u548c\u63d0\u4ea4\u80fd\u5b8c\u5168\u5305\u88f9\u5728\u9501\u7684\u83b7\u53d6\u548c\u91ca\u653e\u4e4b\u95f4\uff0c\u662f\u5426\u53ef\u4ee5\u907f\u514d\u5546\u54c1\u8d85\u5356\u7684\u95ee\u9898\uff1f<\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong><\/p>\n<p>\u662f\u7684\uff0c\u4e8b\u52a1\u63d0\u4ea4\u786e\u5b9e\u5728\u65b9\u6cd5\u8c03\u7528\u7ed3\u675f\u540e\u8fdb\u884c\u3002<\/p>\n<p><strong>\u8be6\u7ec6\u89e3\u91ca\uff1a<\/strong><\/p>\n<p>spring\u4f7f\u7528\u673a\u5236\u5bf9\u6dfb\u52a0\u4e86@transactional\u6ce8\u89e3\u7684\u65b9\u6cd5\u8fdb\u884c\u589e\u5f3a\u3002\u8fd9\u610f\u5473\u7740\u5728\u8be5\u65b9\u6cd5\u6267\u884c\u524d\uff0cspring\u4f1a\u6dfb\u52a0\u4e8b\u52a1\u7684\u5f00\u542f\u903b\u8f91\uff0c\u5728\u65b9\u6cd5\u6267\u884c\u540e\uff0c\u4f1a\u63d0\u4ea4\u4e8b\u52a1\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u4e8b\u52a1\u7684\u5f00\u542f\u548c\u63d0\u4ea4\u786e\u5b9e\u5305\u88f9\u5728\u65b9\u6cd5\u6267\u884c\u7684\u524d\u540e\u3002\u5982\u679c\u5728\u4e00\u4e2a\u65b9\u6cd5\u5185\u4f7f\u7528\u4e86\u9501\uff0c\u5219\u53ef\u4ee5\u786e\u4fdd\u5728\u4e8b\u52a1\u63d0\u4ea4\u4e4b\u524d\u4e0d\u4f1a\u91ca\u653e\u9501\uff0c\u4ece\u800c\u907f\u514d\u4e86\u5728\u8d85\u9ad8\u5e76\u53d1\u60c5\u51b5\u4e0b\u53ef\u80fd\u53d1\u751f\u7684\u8d85\u5356\u95ee\u9898\u3002<\/p>\n<p><strong>\u8865\u5145\uff1a<\/strong><\/p>\n<p>\u4e3a\u4e86\u8fdb\u4e00\u6b65\u907f\u514d\u8d85\u5356\u95ee\u9898\uff0c\u53ef\u4ee5\u5728lock()\u83b7\u53d6\u9501\u4e4b\u540e\u518d\u8c03\u7528\u65b9\u6cd5\uff0c\u7136\u540e\u5728unlock()\u91ca\u653e\u9501\u4e4b\u524d\u63d0\u4ea4\u4e8b\u52a1\uff0c\u786e\u4fdd\u4e8b\u52a1\u5305\u88f9\u4f4f\u6574\u4e2a\u4e1a\u52a1\u903b\u8f91\u3002<\/p>\n<pre>lock();\nmethod();\nunlock();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u66f4\u80fd\u4fdd\u8bc1\u4e8b\u52a1\u7684\u5b8c\u6574\u6027\u548c\u6570\u636e\u7684\u4e00\u81f4\u6027\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5728\u4f7f\u7528\u53ef\u91cd\u590d\u8bfb\u9694\u79bb\u7ea7\u522b\u4e0b\uff0c\u5982\u4f55\u907f\u514d\u4f7f\u7528\u4e8b\u52a1\u6ce8\u89e3 (@Transactional) \u5bfc\u81f4\u7684\u5546\u54c1\u8d85\u5356\u95ee\u9898\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>spring\u4e2d\u7684@transactional\u6ce8\u89e3\uff1a\u4e8b\u52a1\u63d0\u4ea4\u65f6\u673a\u89e3\u6790 \u672c\u7bc7\u6587\u7ae0\u63a2\u8ba8\u4e2d@transactional\u6ce8\u89e3\u5728\u65b9\u6cd5\u6267\u884c\u524d\u540e\u4e8b\u52a1\u63d0\u4ea4\u7684\u65f6\u673a\u3002 \u95ee\u9898\uff1a \u5728\u4f7f\u7528\u53ef\u91cd\u590d\u8bfb\u9694\u79bb\u7ea7\u522b\u7684\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u4e8b\u52a1\u7684\u5f00\u542f\u548c\u63d0\u4ea4\u80fd\u5b8c\u5168\u5305\u88f9\u5728\u9501\u7684\u83b7\u53d6\u548c\u91ca\u653e\u4e4b\u95f4\uff0c\u662f\u5426\u53ef\u4ee5\u907f\u514d\u5546\u54c1\u8d85\u5356\u7684\u95ee\u9898\uff1f \u56de\u7b54\uff1a \u662f\u7684\uff0c\u4e8b\u52a1\u63d0\u4ea4\u786e\u5b9e\u5728\u65b9\u6cd5\u8c03\u7528\u7ed3\u675f\u540e\u8fdb\u884c\u3002 \u8be6\u7ec6\u89e3\u91ca\uff1a spring\u4f7f\u7528\u673a\u5236\u5bf9\u6dfb\u52a0\u4e86@transactional\u6ce8\u89e3\u7684\u65b9\u6cd5\u8fdb\u884c\u589e\u5f3a\u3002\u8fd9\u610f\u5473\u7740\u5728\u8be5\u65b9\u6cd5\u6267\u884c\u524d\uff0cspring\u4f1a\u6dfb\u52a0\u4e8b\u52a1\u7684\u5f00\u542f\u903b\u8f91\uff0c\u5728\u65b9\u6cd5\u6267\u884c\u540e\uff0c\u4f1a\u63d0\u4ea4\u4e8b\u52a1\u3002 \u56e0\u6b64\uff0c\u4e8b\u52a1\u7684\u5f00\u542f\u548c\u63d0\u4ea4\u786e\u5b9e\u5305\u88f9\u5728\u65b9\u6cd5\u6267\u884c\u7684\u524d\u540e\u3002\u5982\u679c\u5728\u4e00\u4e2a\u65b9\u6cd5\u5185\u4f7f\u7528\u4e86\u9501\uff0c\u5219\u53ef\u4ee5\u786e\u4fdd\u5728\u4e8b\u52a1\u63d0\u4ea4\u4e4b\u524d\u4e0d\u4f1a\u91ca\u653e\u9501\uff0c\u4ece\u800c\u907f\u514d\u4e86\u5728\u8d85\u9ad8\u5e76\u53d1\u60c5\u51b5\u4e0b\u53ef\u80fd\u53d1\u751f\u7684\u8d85\u5356\u95ee\u9898\u3002 \u8865\u5145\uff1a \u4e3a\u4e86\u8fdb\u4e00\u6b65\u907f\u514d\u8d85\u5356\u95ee\u9898\uff0c\u53ef\u4ee5\u5728lock()\u83b7\u53d6\u9501\u4e4b\u540e\u518d\u8c03\u7528\u65b9\u6cd5\uff0c\u7136\u540e\u5728unlock()\u91ca\u653e\u9501\u4e4b\u524d\u63d0\u4ea4\u4e8b\u52a1\uff0c\u786e\u4fdd\u4e8b\u52a1\u5305\u88f9\u4f4f\u6574\u4e2a\u4e1a\u52a1\u903b\u8f91\u3002 lock(); method(); unlock(); \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u79cd\u65b9\u5f0f\u66f4\u80fd\u4fdd\u8bc1\u4e8b\u52a1\u7684\u5b8c\u6574\u6027\u548c\u6570\u636e\u7684\u4e00\u81f4\u6027\u3002 \u4ee5\u4e0a\u5c31\u662f\u5728\u4f7f\u7528\u53ef\u91cd\u590d\u8bfb\u9694\u79bb\u7ea7\u522b\u4e0b\uff0c\u5982\u4f55\u907f\u514d\u4f7f\u7528\u4e8b\u52a1\u6ce8\u89e3 (@Transactional) \u5bfc\u81f4\u7684\u5546\u54c1\u8d85\u5356\u95ee\u9898\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-6782","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6782","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=6782"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6782\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}