{"id":320,"date":"2024-07-13T17:12:44","date_gmt":"2024-07-13T09:12:44","guid":{"rendered":"https:\/\/forelink.top\/?p=320"},"modified":"2024-07-13T17:12:44","modified_gmt":"2024-07-13T09:12:44","slug":"2-spring%e4%ba%8b%e5%8a%a1%e8%a7%92%e8%89%b2","status":"publish","type":"post","link":"https:\/\/forelink.top\/index.php\/2024\/07\/13\/2-spring%e4%ba%8b%e5%8a%a1%e8%a7%92%e8%89%b2\/","title":{"rendered":"2.Spring\u4e8b\u52a1\u89d2\u8272"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\" id=\"spring\u4e8b\u52a1\u89d2\u8272\">Spring\u4e8b\u52a1\u89d2\u8272<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u6982\u8ff0\uff1a\">\u6982\u8ff0\uff1a<\/h2>\n\n\n\n<p>\u200b    \u4e3b\u8981\u8bb2\u89e3\u4e86\u4e8b\u52a1\u662f\u5982\u4f55\u5b9e\u73b0\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u6b63\u6587\uff1a\">\u6b63\u6587\uff1a<\/h2>\n\n\n\n<p>\u200b    \u5728\u4e0a\u4e00\u4e2a\u6848\u4f8b\u4e2d\u3002\u7a0b\u5e8f\u6267\u884c\u65f6\uff0c\u4f1a\u8c03\u7528\u5230\u4e24\u4e2a\u9488\u5bf9\u6570\u636e\u7684\u589e\u5220\u6539\u64cd\u4f5c\uff0c\u52a0\u94b1\u548c\u51cf\u94b1\u64cd\u4f5c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public interface AccountDao{\n    @Update(update tbl_account set money = money - #{money} where name = #{name})\n    void outMoney(@Param(\"name\") String name,@Param(\"Money\") Double money);\n    \/\/\u5f00\u542f\u4e8b\u52a1T1\n    \n    @Update(update tbl_account set money = money + #{money} where name = #{name})\n    void inMoney(@Param(\"name\") String name,@Param(\"Money\") Double money);\n    \/\/\u5f00\u542f\u4e8b\u52a1T2\n}\n\/\/\u8c03\u7528\u63a5\u53e3\u4fee\u6539\u6570\u636e\u7684\u65b9\u6cd5\n@Transactional \/\/\u5f00\u542f\u4e8b\u52a1T\npublic void transfer(String out, String in, Double money){\n    accountDao.outMoney(out,money);\n    accountDao.inMoney(in,money);\n}\n<\/code><\/pre>\n\n\n\n<p>\u200b    <\/p>\n\n\n\n<p>\u200b    \u5f00\u542f\u4e8b\u52a1T\u540e\uff0c\u4e8b\u52a1T1,T2 \u90fd\u52a0\u5165\u4e8b\u52a1T\u4e2d\uff0c\u4efb\u4f55\u4e00\u4e2a\u51fa\u73b0\u5f02\u5e38\uff0c\u6574\u4e2a\u8fc7\u7a0b\u90fd\u4f1a\u56de\u6eda\n\u200b    \u4e8b\u52a1\u7ba1\u7406\u5458\uff08\u4e8b\u52a1T\uff09\uff1a\u53d1\u8d77\u4e8b\u52a1\u65b9\uff0c\u5728Spring\u4e2d\u901a\u5e38\u6307\u4e1a\u52a1\u5c42\u5f00\u542f\u4e8b\u52a1\u7684\u65b9\u6cd5\n\u200b    \u4e8b\u52a1\u534f\u8c03\u5458\uff08\u4e8b\u52a1T1,T2)\uff1a\u52a0\u5165\u4e8b\u52a1\u65b9\uff0c\u5728Spring\u4e2d\u901a\u5e38\u6307\u6570\u636e\u5c42\u65b9\u6cd5\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e1a\u52a1\u5c42\u65b9\u6cd5<\/p>\n\n\n\n<p>\u200b    \u4f5c\u7528\uff1a\u5c06\u591a\u4e2a\u4e8b\u52a1\u7ba1\u7406\u6210\u4e00\u4e2a\u4e8b\u52a1<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u6ce8\u610f\u4e8b\u9879\uff1a\">\u6ce8\u610f\u4e8b\u9879\uff1a<\/h2>\n\n\n\n<p>\u200b    \u4e8b\u52a1\u7ba1\u7406\u5668 <strong>DataSourceTransactionManager<\/strong> \u4e2d\u7528\u5230\u7684 <strong>DataSource<\/strong>\uff0c\u5e94\u8be5\u548c <strong>MybatisConfig<\/strong> \u4e2d\u7684 <strong>sqlSessionFactory<\/strong> \u7528\u540c\u4e00\u4e2a <strong>DataSource<\/strong> \uff0c\u4e8b\u52a1\u624d\u80fd\u7edf\u4e00\u7ba1\u7406\uff0c\u5426\u5219T1,T2\u4e0d\u80fd\u88abT\u7ba1\u7406<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spring\u4e8b\u52a1\u89d2\u8272 \u6982\u8ff0\uff1a \u200b \u4e3b\u8981\u8bb2\u89e3\u4e86\u4e8b\u52a1\u662f\u5982\u4f55\u5b9e\u73b0\u7684\u3002 \u6b63\u6587\uff1a \u200b \u5728\u4e0a\u4e00\u4e2a\u6848\u4f8b\u4e2d\u3002\u7a0b\u5e8f\u6267\u884c\u65f6\uff0c\u4f1a\u8c03\u7528 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[28,17],"tags":[],"class_list":["post-320","post","type-post","status-publish","format-standard","hentry","category-spring","category-17"],"_links":{"self":[{"href":"https:\/\/forelink.top\/index.php\/wp-json\/wp\/v2\/posts\/320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/forelink.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/forelink.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/forelink.top\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/forelink.top\/index.php\/wp-json\/wp\/v2\/comments?post=320"}],"version-history":[{"count":1,"href":"https:\/\/forelink.top\/index.php\/wp-json\/wp\/v2\/posts\/320\/revisions"}],"predecessor-version":[{"id":321,"href":"https:\/\/forelink.top\/index.php\/wp-json\/wp\/v2\/posts\/320\/revisions\/321"}],"wp:attachment":[{"href":"https:\/\/forelink.top\/index.php\/wp-json\/wp\/v2\/media?parent=320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/forelink.top\/index.php\/wp-json\/wp\/v2\/categories?post=320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/forelink.top\/index.php\/wp-json\/wp\/v2\/tags?post=320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}