{"id":106767,"date":"2026-09-18T09:49:02","date_gmt":"2026-09-18T01:49:02","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/106767.html"},"modified":"2026-09-18T09:49:02","modified_gmt":"2026-09-18T01:49:02","slug":"mybatis-%e7%bc%93%e5%ad%98%e6%9c%ba%e5%88%b6%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/106767.html","title":{"rendered":"MyBatis \u7f13\u5b58\u673a\u5236\u8be6\u89e3"},"content":{"rendered":"<h2>MyBatis \u7f13\u5b58\u673a\u5236\u8be6\u89e3<\/h2>\n<p>\u5b9a\u4f4d&#xff1a;MyBatis \u7cfb\u5217\u7b2c 4 \u7bc7\u2014\u2014\u4e00\u7ea7\u7f13\u5b58\u4e0e\u4e8c\u7ea7\u7f13\u5b58\u7684\u5b8c\u6574\u673a\u5236\u3001\u810f\u8bfb\u5206\u6790\u4e0e\u751f\u4ea7\u5b9e\u8df5\u7ed3\u8bba \u9002\u7528\u7248\u672c&#xff1a;MyBatis 3.5.x&#xff08;JDK 8&#043;&#xff09;<\/p>\n<hr \/>\n<h3>\u76ee\u5f55<\/h3>\n<li>\u7f13\u5b58\u5168\u666f<\/li>\n<li>\u4e00\u7ea7\u7f13\u5b58&#xff08;Local Cache&#xff09;<\/li>\n<li>\u4e00\u7ea7\u7f13\u5b58\u810f\u8bfb\u5206\u6790<\/li>\n<li>\u4e8c\u7ea7\u7f13\u5b58&#xff08;Global Cache&#xff09;<\/li>\n<li>\u7f13\u5b58\u6267\u884c\u987a\u5e8f\u4e0e\u88c5\u9970\u7ed3\u6784<\/li>\n<li>\u751f\u4ea7\u5b9e\u8df5\u4e0e\u5916\u90e8\u7f13\u5b58\u6574\u5408<\/li>\n<li>\u603b\u7ed3<\/li>\n<li>\u5e38\u89c1\u9ad8\u9891\u9762\u8bd5\u9898<\/li>\n<hr \/>\n<h3>\u4e00\u3001\u7f13\u5b58\u5168\u666f<\/h3>\n<p>MyBatis \u5185\u5efa\u4e24\u7ea7\u7f13\u5b58&#xff0c;\u67e5\u8be2\u65f6\u4f9d\u6b21\u7ecf\u8fc7&#xff1a;<\/p>\n<p>SELECT \u67e5\u8be2\u8def\u5f84&#xff1a;<br \/>\n  \u4e8c\u7ea7\u7f13\u5b58&#xff08;namespace \u7ea7&#xff0c;\u8de8 SqlSession&#xff09;<br \/>\n      \u2502 \u672a\u547d\u4e2d<br \/>\n      \u25bc<br \/>\n  \u4e00\u7ea7\u7f13\u5b58&#xff08;SqlSession \u7ea7&#xff09;<br \/>\n      \u2502 \u672a\u547d\u4e2d<br \/>\n      \u25bc<br \/>\n  \u6570\u636e\u5e93<br \/>\n      \u2502 \u7ed3\u679c\u56de\u586b<br \/>\n      \u25bc<br \/>\n  \u4e00\u7ea7\u7f13\u5b58\u7acb\u5373\u5199\u5165&#xff1b;\u4e8c\u7ea7\u7f13\u5b58\u5728\u4e8b\u52a1\u63d0\u4ea4\u540e\u5199\u5165<\/p>\n<table>\n<tr>\u7ef4\u5ea6\u4e00\u7ea7\u7f13\u5b58\u4e8c\u7ea7\u7f13\u5b58<\/tr>\n<tbody>\n<tr>\n<td>\u4f5c\u7528\u57df<\/td>\n<td>SqlSession \u751f\u547d\u5468\u671f<\/td>\n<td>namespace&#xff08;Mapper&#xff09;\u7ea7<\/td>\n<\/tr>\n<tr>\n<td>\u9ed8\u8ba4\u72b6\u6001<\/td>\n<td>\u5f00\u542f&#xff0c;\u65e0\u9700\u914d\u7f6e<\/td>\n<td>\u5173\u95ed&#xff0c;\u9700\u663e\u5f0f\u5f00\u542f<\/td>\n<\/tr>\n<tr>\n<td>\u627f\u8f7d\u8005<\/td>\n<td>BaseExecutor.localCache<\/td>\n<td>MappedStatement \u7ed1\u5b9a\u7684 Cache &#043; CachingExecutor<\/td>\n<\/tr>\n<tr>\n<td>\u8de8\u4f1a\u8bdd<\/td>\n<td>\u5426<\/td>\n<td>\u662f<\/td>\n<\/tr>\n<tr>\n<td>\u5173\u95ed\u65b9\u5f0f<\/td>\n<td>\u53ea\u80fd\u7f29\u5c0f\u4f5c\u7528\u57df&#xff08;localCacheScope&#xff09;<\/td>\n<td>\u4e0d\u914d\u7f6e &lt;cache\/&gt; \u5373\u5173\u95ed<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7f13\u5b58\u952e\u4e0e\u503c&#xff1a;\u952e\u662f CacheKey&#xff08;\u89c1 2.2&#xff09;&#xff0c;\u503c\u662f\u67e5\u8be2\u7ed3\u679c\u5bf9\u8c61\u5217\u8868&#xff1b;\u5e95\u5c42\u90fd\u662f PerpetualCache&#xff08;HashMap \u5305\u88c5&#xff09;&#xff0c;\u4e8c\u7ea7\u7f13\u5b58\u989d\u5916\u53e0\u52a0\u6dd8\u6c70\u7b56\u7565\u7b49\u88c5\u9970\u5668&#xff08;\u89c1\u7b2c\u4e94\u8282&#xff09;\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u4e00\u7ea7\u7f13\u5b58&#xff08;Local Cache&#xff09;<\/h3>\n<h4>2.1 \u57fa\u672c\u7279\u5f81<\/h4>\n<ul>\n<li>\u5b9e\u73b0&#xff1a;BaseExecutor \u5185\u7684 localCache \u5b57\u6bb5&#xff08;PerpetualCache&#xff09;&#xff0c;\u67e5\u8be2\u5165\u53e3 BaseExecutor.query \u5148\u67e5\u7f13\u5b58\u3002<\/li>\n<li>\u9ed8\u8ba4\u5f00\u542f&#xff0c;\u6ca1\u6709\u914d\u7f6e\u9879\u53ef\u4ee5\u6574\u4f53\u5173\u95ed\u2014\u2014\u53ea\u80fd\u901a\u8fc7 localCacheScope&#061;STATEMENT \u628a\u4f5c\u7528\u57df\u7f29\u5c0f\u5230\u8bed\u53e5\u7ea7\u3002<\/li>\n<li>\u540c\u4e00\u6b21\u67e5\u8be2&#xff08;\u76f8\u540c\u7f13\u5b58\u952e&#xff09;\u5728\u540c\u4e00\u4f1a\u8bdd\u5185\u91cd\u590d\u6267\u884c&#xff0c;\u7b2c\u4e8c\u6b21\u76f4\u63a5\u8fd4\u56de\u7f13\u5b58\u7ed3\u679c&#xff0c;\u4e0d\u518d\u8bbf\u95ee\u6570\u636e\u5e93\u3002<\/li>\n<\/ul>\n<h4>2.2 CacheKey \u6784\u6210<\/h4>\n<p>CacheKey &#061; statementId&#xff08;namespace.\u65b9\u6cd5\u540d&#xff09;<br \/>\n         &#043; RowBounds&#xff08;offset \/ limit&#xff09;<br \/>\n         &#043; BoundSql \u7684 SQL \u6587\u672c<br \/>\n         &#043; \u5404\u53c2\u6570\u503c&#xff08;\u6309 parameterMappings \u987a\u5e8f&#xff09;<br \/>\n         &#043; environment id<\/p>\n<p>\u4efb\u4e00\u8981\u7d20\u4e0d\u540c\u5373\u89c6\u4e3a\u4e0d\u540c\u67e5\u8be2\u3002\u8fd9\u89e3\u91ca\u4e86&#xff1a;\u540c\u4e00\u65b9\u6cd5\u4e0d\u540c\u53c2\u6570\u4e0d\u4f1a\u4e92\u76f8\u6c61\u67d3\u7f13\u5b58&#xff1b;\u800c\u52a8\u6001 SQL \u62fc\u51fa\u7684\u4e0d\u540c SQL \u6587\u672c\u4e5f\u4f1a\u4ea7\u751f\u4e0d\u540c\u7f13\u5b58\u952e\u3002<\/p>\n<h4>2.3 \u5931\u6548\u65f6\u673a<\/h4>\n<p>\u4ee5\u4e0b\u4efb\u4e00\u60c5\u51b5\u53d1\u751f\u540e&#xff0c;\u4f1a\u8bdd\u7684\u4e00\u7ea7\u7f13\u5b58\u88ab\u6e05\u7a7a&#xff1a;<\/p>\n<table>\n<tr>\u65f6\u673a\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>insert \/ update \/ delete \u6267\u884c\u540e<\/td>\n<td>\u540c\u4f1a\u8bdd\u4efb\u610f\u5199\u8bed\u53e5&#xff08;\u65e0\u8bba\u662f\u5426\u5f71\u54cd\u7f13\u5b58\u4e2d\u7684\u6570\u636e&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>commit \/ rollback<\/td>\n<td>\u4e8b\u52a1\u8fb9\u754c<\/td>\n<\/tr>\n<tr>\n<td>close<\/td>\n<td>\u4f1a\u8bdd\u5173\u95ed<\/td>\n<\/tr>\n<tr>\n<td>flushCache&#061;&#034;true&#034;<\/td>\n<td>\u8bed\u53e5\u7ea7\u5f3a\u5236\u5237\u65b0&#xff08;\u67e5\u8be2\u8bed\u53e5\u4e5f\u53ef\u8bbe\u7f6e&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>session.clearCache()<\/td>\n<td>\u624b\u52a8\u6e05\u7a7a&#xff08;\u4e0d\u6e05\u7406\u4e8c\u7ea7\u7f13\u5b58&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6ce8\u610f&#xff1a;\u5199\u64cd\u4f5c\u6e05\u7a7a\u7684\u662f\u6574\u4e2a\u4f1a\u8bdd\u7f13\u5b58&#xff0c;\u4e0d\u662f\u7cbe\u51c6\u5931\u6548\u67d0\u6761\u7f13\u5b58\u2014\u2014MyBatis \u4e0d\u505a\u4f9d\u8d56\u5206\u6790&#xff08;\u4e0d\u77e5\u9053\u54ea\u6761\u67e5\u8be2\u4f9d\u8d56\u4e86\u88ab\u66f4\u65b0\u7684\u8868&#xff09;\u3002<\/p>\n<h4>2.4 localCacheScope<\/h4>\n<p><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>settings<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>setting<\/span> <span class=\"token attr-name\">name<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>localCacheScope<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">value<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>SESSION<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">\/&gt;<\/span><\/span>   <span class=\"token comment\">&lt;!&#8211; \u9ed8\u8ba4&#xff1a;\u4f1a\u8bdd\u7ea7 &#8211;&gt;<\/span><br \/>\n    <span class=\"token comment\">&lt;!&#8211; &lt;setting name&#061;&#034;localCacheScope&#034; value&#061;&#034;STATEMENT&#034;\/&gt; &#8211;&gt;<\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>settings<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><\/p>\n<p>STATEMENT \u6a21\u5f0f\u4e0b\u6bcf\u6761\u8bed\u53e5\u6267\u884c\u5b8c\u5373\u6e05\u7a7a\u4e00\u7ea7\u7f13\u5b58&#xff0c;\u7b49\u4ef7\u4e8e\u653e\u5f03\u4f1a\u8bdd\u5185\u91cd\u590d\u67e5\u8be2\u4f18\u5316&#xff0c;\u7528\u4e8e\u89c4\u907f\u7279\u5b9a\u810f\u8bfb\u573a\u666f&#xff08;\u89c1\u7b2c\u4e09\u8282&#xff09;\u3002<\/p>\n<h4>2.5 Spring \u6574\u5408\u4e0b\u7684\u5b9e\u9645\u8868\u73b0&#xff08;\u91cd\u8981&#xff09;<\/h4>\n<p>SqlSessionTemplate \u5728\u65e0\u4e8b\u52a1\u573a\u666f\u4e0b&#xff0c;\u6bcf\u6b21 Mapper \u65b9\u6cd5\u8c03\u7528\u90fd\u521b\u5efa\u72ec\u7acb SqlSession\u3001\u6267\u884c\u5b8c\u5373\u5173\u95ed\u2014\u2014\u56e0\u6b64\u4e00\u7ea7\u7f13\u5b58\u5728\u4e24\u6b21\u72ec\u7acb\u8c03\u7528\u4e4b\u95f4\u57fa\u672c\u4e0d\u4f1a\u547d\u4e2d\u3002\u53ea\u6709\u5728\u540c\u4e00 &#064;Transactional \u65b9\u6cd5\u5185&#xff0c;\u4e8b\u52a1\u540c\u6b65\u673a\u5236\u8ba9\u591a\u6b21\u8c03\u7528\u5171\u4eab\u540c\u4e00 SqlSession&#xff0c;\u4e00\u7ea7\u7f13\u5b58\u624d\u771f\u6b63\u751f\u6548\u3002<\/p>\n<p>\u63a8\u8bba&#xff1a;\u5f88\u591a\u56e2\u961f\u300c\u4e00\u7ea7\u7f13\u5b58\u6ca1\u8d77\u4f5c\u7528\u300d\u7684\u56f0\u60d1&#xff0c;\u6839\u6e90\u5c31\u662f\u65e0\u4e8b\u52a1\u8c03\u7528\u6a21\u5f0f&#xff1b;\u8fd9\u4e0d\u662f Bug&#xff0c;\u662f SqlSessionTemplate \u7684\u751f\u547d\u5468\u671f\u8bbe\u8ba1\u3002<\/p>\n<hr \/>\n<h3>\u4e09\u3001\u4e00\u7ea7\u7f13\u5b58\u810f\u8bfb\u5206\u6790<\/h3>\n<h4>3.1 \u573a\u666f\u8fd8\u539f&#xff08;\u6559\u5b66\u793a\u4f8b&#xff09;<\/h4>\n<p>\u65f6\u95f4\u8f74&#xff1a;<br \/>\n  t1  \u4f1a\u8bddA&#xff1a;SELECT * FROM user WHERE id &#061; 1   \u2192 name&#061;&#039;\u5f20\u4e09&#039;&#xff0c;\u5199\u5165 A \u7684\u4e00\u7ea7\u7f13\u5b58<br \/>\n  t2  \u4f1a\u8bddB&#xff1a;UPDATE user SET name&#061;&#039;\u674e\u56db&#039; WHERE id &#061; 1&#xff1b;\u63d0\u4ea4<br \/>\n  t3  \u4f1a\u8bddA&#xff1a;SELECT * FROM user WHERE id &#061; 1   \u2192 \u547d\u4e2d\u4e00\u7ea7\u7f13\u5b58&#xff0c;\u8fd4\u56de&#039;\u5f20\u4e09&#039;&#xff08;\u810f\u8bfb&#xff09;<br \/>\n  t4  \u4f1a\u8bddA&#xff1a;\u4efb\u610f\u5199\u64cd\u4f5c\/commit\/close           \u2192 \u7f13\u5b58\u6e05\u7a7a&#xff0c;\u4e4b\u540e\u67e5\u8be2\u624d\u80fd\u8bfb\u5230&#039;\u674e\u56db&#039;<\/p>\n<h4>3.2 \u7a97\u53e3\u4e0e\u672c\u8d28<\/h4>\n<ul>\n<li>\u7a97\u53e3\u671f&#xff1a;A \u9996\u6b21\u67e5\u8be2\u4e4b\u540e&#xff0c;\u5230 A \u4f1a\u8bdd\u5185\u53d1\u751f\u4efb\u4f55\u5199\u64cd\u4f5c\/\u5173\u95ed\u4e4b\u524d\u3002<\/li>\n<li>\u672c\u8d28&#xff1a;\u7f13\u5b58\u8bfb\u53d6\u7ed5\u8fc7\u4e86\u6570\u636e\u5e93&#xff0c;\u6570\u636e\u5e93\u9694\u79bb\u7ea7\u522b&#xff08;\u5373\u4f7f SERIALIZABLE&#xff09;\u4e5f\u7ba1\u4e0d\u5230\u5e94\u7528\u8fdb\u7a0b\u5185\u7684 HashMap\u3002<\/li>\n<li>\u5f71\u54cd\u653e\u5927&#xff1a;\u957f\u4f1a\u8bdd&#xff08;\u5982\u6279\u5904\u7406\u4efb\u52a1\u4e2d\u4e00\u4e2a SqlSession \u5904\u7406\u6574\u4e2a\u6279\u6b21&#xff09;\u7a97\u53e3\u66f4\u5927&#xff1b;\u5206\u5e03\u5f0f\u591a\u8282\u70b9\u4e0b\u5404\u8282\u70b9\u7684\u4f1a\u8bdd\u7f13\u5b58\u4e92\u4e0d\u611f\u77e5\u3002<\/li>\n<\/ul>\n<h4>3.3 \u7f13\u89e3\u624b\u6bb5<\/h4>\n<table>\n<tr>\u624b\u6bb5\u4ee3\u4ef7<\/tr>\n<tbody>\n<tr>\n<td>localCacheScope&#061;STATEMENT<\/td>\n<td>\u653e\u5f03\u4f1a\u8bdd\u5185\u91cd\u590d\u67e5\u8be2\u4f18\u5316<\/td>\n<\/tr>\n<tr>\n<td>\u7f29\u77ed SqlSession \u751f\u547d\u5468\u671f<\/td>\n<td>Spring \u65e0\u4e8b\u52a1\u6a21\u5f0f\u5929\u7136\u5982\u6b64<\/td>\n<\/tr>\n<tr>\n<td>\u5173\u952e\u4e1a\u52a1\u8bfb\u540e\u6821\u9a8c \/ flushCache&#061;&#034;true&#034;<\/td>\n<td>\u8bed\u53e5\u7ea7\u7cbe\u51c6\u63a7\u5236&#xff0c;\u589e\u52a0 DB \u538b\u529b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u56db\u3001\u4e8c\u7ea7\u7f13\u5b58&#xff08;Global Cache&#xff09;<\/h3>\n<h4>4.1 \u5f00\u542f\u65b9\u5f0f<\/h4>\n<p><span class=\"token comment\">&lt;!&#8211; Mapper XML&#xff1a;namespace \u7ea7\u5f00\u542f &#8211;&gt;<\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>mapper<\/span> <span class=\"token attr-name\">namespace<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>com.example.mapper.UserMapper<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>cache<\/span> <span class=\"token attr-name\">eviction<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>LRU<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">flushInterval<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>60000<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">size<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>512<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">readOnly<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>false<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">\/&gt;<\/span><\/span><br \/>\n    &#8230;<br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>mapper<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u6ce8\u89e3\u65b9\u5f0f<\/span><br \/>\n<span class=\"token annotation punctuation\">&#064;CacheNamespace<\/span><span class=\"token punctuation\">(<\/span>eviction <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name\">LruCache<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">,<\/span> flushInterval <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">60000<\/span><span class=\"token punctuation\">,<\/span> size <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">512<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">interface<\/span> <span class=\"token class-name\">UserMapper<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span> <span class=\"token punctuation\">}<\/span><\/p>\n<p>\u524d\u63d0&#xff1a;\u5168\u5c40 cacheEnabled&#061;true&#xff08;\u9ed8\u8ba4\u5373\u4e3a true&#xff0c;\u4ec5\u63a7\u5236\u662f\u5426\u5141\u8bb8&#xff09;&#xff1b;readOnly&#061;false&#xff08;\u9ed8\u8ba4&#xff09;\u65f6\u5b9e\u4f53\u7c7b\u5fc5\u987b\u5b9e\u73b0 Serializable\u2014\u2014\u7f13\u5b58\u5b58\u53d6\u7684\u662f\u5e8f\u5217\u5316\u526f\u672c\u3002<\/p>\n<h4>4.2 cache \u5c5e\u6027\u8be6\u89e3<\/h4>\n<table>\n<tr>\u5c5e\u6027\u9ed8\u8ba4\u503c\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>eviction<\/td>\n<td>LRU<\/td>\n<td>\u6dd8\u6c70\u7b56\u7565&#xff1a;LRU&#xff08;\u6700\u8fd1\u6700\u5c11\u4f7f\u7528&#xff09;\/ FIFO \/ SOFT&#xff08;\u8f6f\u5f15\u7528&#xff09;\/ WEAK&#xff08;\u5f31\u5f15\u7528&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>flushInterval<\/td>\n<td>\u4e0d\u8bbe\u7f6e<\/td>\n<td>\u5b9a\u65f6\u5168\u91cf\u6e05\u7a7a\u95f4\u9694&#xff08;\u6beb\u79d2&#xff09;&#xff1b;\u4e0d\u8bbe\u7f6e\u5219\u53ea\u9760\u5199\u64cd\u4f5c\u89e6\u53d1\u5237\u65b0<\/td>\n<\/tr>\n<tr>\n<td>size<\/td>\n<td>512<\/td>\n<td>\u6700\u591a\u7f13\u5b58\u591a\u5c11\u4e2a\u300c\u8bed\u53e5\u7ed3\u679c\u300d\u6761\u76ee<\/td>\n<\/tr>\n<tr>\n<td>readOnly<\/td>\n<td>false<\/td>\n<td>false&#xff1a;\u8fd4\u56de\u5e8f\u5217\u5316\u526f\u672c&#xff08;\u5b89\u5168\u3001\u6709\u5f00\u9500&#xff09;&#xff1b;true&#xff1a;\u8fd4\u56de\u5171\u4eab\u5f15\u7528&#xff08;\u5feb&#xff0c;\u4f46\u8c03\u7528\u65b9\u4fee\u6539\u4f1a\u6c61\u67d3\u7f13\u5b58&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>4.3 \u5199\u5165\u4e0e\u5237\u65b0\u673a\u5236<\/h4>\n<p>\u5199\u5165\u65f6\u673a\u2014\u2014TransactionalCache&#xff1a;\u4e8c\u7ea7\u7f13\u5b58\u88ab TransactionalCache \u88c5\u9970&#xff0c;\u67e5\u8be2\u7ed3\u679c\u5148\u653e\u5165\u4e8b\u52a1\u4e34\u65f6\u533a&#xff0c;\u4e8b\u52a1\u63d0\u4ea4&#xff08;\u6216\u4f1a\u8bdd\u5173\u95ed&#xff09;\u540e\u624d\u771f\u6b63\u5199\u5165\u7f13\u5b58\u2014\u2014\u907f\u514d\u672a\u63d0\u4ea4\u6570\u636e\u88ab\u5176\u4ed6\u4f1a\u8bdd\u8bfb\u5230\u3002<\/p>\n<p>\u5237\u65b0\u65f6\u673a&#xff1a;\u8be5 namespace \u5185\u4efb\u610f C\/U\/D \u8bed\u53e5\u6267\u884c\u540e\u6e05\u7a7a\u6574\u4e2a namespace \u7f13\u5b58&#xff08;\u5199\u8bed\u53e5 flushCache \u9ed8\u8ba4\u4e3a true&#xff09;\u3002\u8bed\u53e5\u7ea7\u63a7\u5236&#xff1a;<\/p>\n<p><span class=\"token comment\">&lt;!&#8211; \u8be5\u67e5\u8be2\u4e0d\u4f7f\u7528\u4e8c\u7ea7\u7f13\u5b58 &#8211;&gt;<\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>select<\/span> <span class=\"token attr-name\">id<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>selectRealtime<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">useCache<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>false<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">&#8230;<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><\/p>\n<p><span class=\"token comment\">&lt;!&#8211; \u8be5\u67e5\u8be2\u6267\u884c\u524d\u5f3a\u5236\u5237\u65b0\u4e8c\u7ea7\u7f13\u5b58 &#8211;&gt;<\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>select<\/span> <span class=\"token attr-name\">id<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>selectFresh<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">flushCache<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>true<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">&#8230;<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><\/p>\n<h4>4.4 \u4e24\u7c7b\u7ecf\u5178\u810f\u8bfb<\/h4>\n<p>\u810f\u8bfb\u4e00&#xff1a;\u8de8 namespace<\/p>\n<p>\u573a\u666f&#xff08;\u6559\u5b66\u793a\u4f8b&#xff09;&#xff1a;<br \/>\n  OrderMapper.selectOrderWithUser&#xff1a;JOIN user \u8868&#xff0c;\u7ed3\u679c\u8fdb\u5165 OrderMapper namespace \u7f13\u5b58<br \/>\n  UserMapper.updateName&#xff1a;\u66f4\u65b0 user \u8868 \u2192 \u53ea\u5237\u65b0 UserMapper namespace \u7f13\u5b58<br \/>\n  \u2192 OrderMapper \u7684 JOIN \u7f13\u5b58\u4ecd\u65e7\u6709\u6548&#xff0c;\u8fd4\u56de\u8fc7\u671f\u7684\u7528\u6237\u540d<\/p>\n<p>MyBatis \u4e0d\u8ffd\u8e2a SQL \u4f9d\u8d56\u4e86\u54ea\u4e9b\u8868&#xff0c;\u7f13\u5b58\u5931\u6548\u4ee5 namespace \u4e3a\u5355\u4f4d&#xff0c;\u8de8 namespace \u7684\u8868\u4f9d\u8d56\u5fc5\u7136\u51fa\u73b0\u5931\u6548\u76f2\u533a\u3002<\/p>\n<p>\u810f\u8bfb\u4e8c&#xff1a;\u591a\u8282\u70b9<\/p>\n<p>\u96c6\u7fa4\u90e8\u7f72&#xff1a;<br \/>\n  \u8282\u70b9A\u3001\u8282\u70b9B \u5404\u81ea\u6301\u6709\u672c\u5730\u4e8c\u7ea7\u7f13\u5b58&#xff08;JVM \u5185\u5b58 HashMap&#xff09;<br \/>\n  \u8282\u70b9A \u6267\u884c\u66f4\u65b0 \u2192 \u53ea\u5237\u65b0\u8282\u70b9A \u81ea\u5df1\u7684\u7f13\u5b58<br \/>\n  \u2192 \u6d41\u91cf\u6253\u5230\u8282\u70b9B \u65f6\u6301\u7eed\u8bfb\u5230\u65e7\u503c&#xff0c;\u4e14\u65e0\u5931\u6548\u5e7f\u64ad<\/p>\n<h4>4.5 \u7ed3\u8bba<\/h4>\n<p>\u4e8c\u7ea7\u7f13\u5b58\u7684\u8bbe\u8ba1\u76ee\u6807\u662f\u300c\u5355 namespace \u53ea\u8bfb\u4e3a\u4e3b\u7684\u6570\u636e\u52a0\u901f\u300d&#xff0c;\u5176\u5931\u6548\u7c92\u5ea6&#xff08;namespace&#xff09;\u4e0e\u90e8\u7f72\u5f62\u6001&#xff08;\u5355\u673a JVM&#xff09;\u90fd\u96be\u4ee5\u5339\u914d\u73b0\u4ee3\u5fae\u670d\u52a1\u573a\u666f\u3002\u751f\u4ea7\u73af\u5883\u4e00\u822c\u4e0d\u5f00\u542f\u4e8c\u7ea7\u7f13\u5b58&#xff0c;\u7f13\u5b58\u9700\u6c42\u4ea4\u7ed9\u5e94\u7528\u5c42\u5916\u90e8\u7f13\u5b58&#xff08;\u89c1\u7b2c\u516d\u8282&#xff09;\u3002<\/p>\n<hr \/>\n<h3>\u4e94\u3001\u7f13\u5b58\u6267\u884c\u987a\u5e8f\u4e0e\u88c5\u9970\u7ed3\u6784<\/h3>\n<h4>5.1 \u67e5\u8be2\u5b8c\u6574\u8def\u5f84<\/h4>\n<p><span class=\"token comment\">\/\/ CachingExecutor.query&#xff08;\u7b80\u5316&#xff09;<\/span><br \/>\n<span class=\"token class-name\">Cache<\/span> cache <span class=\"token operator\">&#061;<\/span> ms<span class=\"token punctuation\">.<\/span><span class=\"token function\">getCache<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>                     <span class=\"token comment\">\/\/ \u8be5\u8bed\u53e5\u6240\u5c5e namespace \u7684\u4e8c\u7ea7\u7f13\u5b58<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>cache <span class=\"token operator\">!&#061;<\/span> <span class=\"token keyword\">null<\/span> <span class=\"token operator\">&amp;&amp;<\/span> ms<span class=\"token punctuation\">.<\/span><span class=\"token function\">isUseCache<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token class-name\">List<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">E<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> result <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token class-name\">List<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">E<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><span class=\"token punctuation\">)<\/span> tcm<span class=\"token punctuation\">.<\/span><span class=\"token function\">getObject<\/span><span class=\"token punctuation\">(<\/span>cache<span class=\"token punctuation\">,<\/span> key<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u67e5\u4e8c\u7ea7\u7f13\u5b58<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>result <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        result <span class=\"token operator\">&#061;<\/span> delegate<span class=\"token punctuation\">.<\/span><span class=\"token function\">query<\/span><span class=\"token punctuation\">(<\/span>ms<span class=\"token punctuation\">,<\/span> param<span class=\"token punctuation\">,<\/span> rowBounds<span class=\"token punctuation\">,<\/span> handler<span class=\"token punctuation\">,<\/span> key<span class=\"token punctuation\">,<\/span> boundSql<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/      \u2191 \u59d4\u6258\u88ab\u88c5\u9970 Executor&#xff08;BaseExecutor \u5185\u90e8\u518d\u67e5\u4e00\u7ea7\u7f13\u5b58&#xff09;<\/span><br \/>\n        tcm<span class=\"token punctuation\">.<\/span><span class=\"token function\">putObject<\/span><span class=\"token punctuation\">(<\/span>cache<span class=\"token punctuation\">,<\/span> key<span class=\"token punctuation\">,<\/span> result<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/ \u6682\u5b58&#xff0c;\u63d0\u4ea4\u540e\u751f\u6548<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> result<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token keyword\">return<\/span> delegate<span class=\"token punctuation\">.<\/span><span class=\"token function\">query<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ BaseExecutor.query&#xff08;\u7b80\u5316&#xff09;&#xff1a;\u4e00\u7ea7\u7f13\u5b58<\/span><br \/>\n<span class=\"token class-name\">List<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">E<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> result <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token class-name\">List<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">E<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><span class=\"token punctuation\">)<\/span> localCache<span class=\"token punctuation\">.<\/span><span class=\"token function\">getObject<\/span><span class=\"token punctuation\">(<\/span>key<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>result <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    result <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">queryFromDatabase<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>             <span class=\"token comment\">\/\/ \u771f\u6b63\u6267\u884c SQL<\/span><br \/>\n    localCache<span class=\"token punctuation\">.<\/span><span class=\"token function\">putObject<\/span><span class=\"token punctuation\">(<\/span>key<span class=\"token punctuation\">,<\/span> result<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token keyword\">return<\/span> result<span class=\"token punctuation\">;<\/span><\/p>\n<h4>5.2 Cache \u88c5\u9970\u94fe<\/h4>\n<p>MyBatis \u7528\u88c5\u9970\u5668\u6a21\u5f0f\u7ec4\u5408\u7f13\u5b58\u80fd\u529b&#xff0c;&lt;cache\/&gt; \u7684\u5178\u578b\u88c5\u914d\u7ed3\u679c&#xff1a;<\/p>\n<p>TransactionalCache&#xff08;\u63d0\u4ea4\u65f6\u624d\u5199\u5165&#xff09;<br \/>\n  \u2514\u2500\u2500 SynchronizedCache&#xff08;\u5e76\u53d1\u5b89\u5168&#xff09;<br \/>\n        \u2514\u2500\u2500 LoggingCache&#xff08;\u547d\u4e2d\u7387\u65e5\u5fd7&#xff09;<br \/>\n              \u2514\u2500\u2500 SerializedCache&#xff08;readOnly&#061;false \u65f6\u7684\u5e8f\u5217\u5316\u526f\u672c&#xff09;<br \/>\n                    \u2514\u2500\u2500 LruCache&#xff08;\u6dd8\u6c70\u7b56\u7565&#xff09;<br \/>\n                          \u2514\u2500\u2500 PerpetualCache&#xff08;HashMap \u57fa\u7840\u5b9e\u73b0&#xff09;<\/p>\n<p>\u5404\u88c5\u9970\u5668\u804c\u8d23&#xff1a;<\/p>\n<table>\n<tr>\u88c5\u9970\u5668\u804c\u8d23<\/tr>\n<tbody>\n<tr>\n<td>PerpetualCache<\/td>\n<td>HashMap \u5b58\u53d6&#xff0c;\u4e00\u5207\u7f13\u5b58\u7684\u5730\u57fa<\/td>\n<\/tr>\n<tr>\n<td>LruCache \/ FifoCache \/ SoftCache \/ WeakCache<\/td>\n<td>\u6dd8\u6c70\u7b56\u7565<\/td>\n<\/tr>\n<tr>\n<td>SerializedCache<\/td>\n<td>\u5b58\u53d6\u65f6\u5e8f\u5217\u5316\/\u53cd\u5e8f\u5217\u5316&#xff0c;\u4fdd\u8bc1\u8fd4\u56de\u526f\u672c<\/td>\n<\/tr>\n<tr>\n<td>LoggingCache<\/td>\n<td>\u8bb0\u5f55\u547d\u4e2d\u7387<\/td>\n<\/tr>\n<tr>\n<td>SynchronizedCache<\/td>\n<td>synchronized \u5305\u88c5<\/td>\n<\/tr>\n<tr>\n<td>TransactionalCache<\/td>\n<td>\u4e8b\u52a1\u63d0\u4ea4\u524d\u6682\u5b58&#xff0c;\u63d0\u4ea4\u540e\u63d0\u4ea4\u5230\u4e0b\u5c42<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u516d\u3001\u751f\u4ea7\u5b9e\u8df5\u4e0e\u5916\u90e8\u7f13\u5b58\u6574\u5408<\/h3>\n<h4>6.1 \u5b9e\u8df5\u7ed3\u8bba<\/h4>\n<table>\n<tr>\u7f13\u5b58\u5efa\u8bae<\/tr>\n<tbody>\n<tr>\n<td>\u4e00\u7ea7\u7f13\u5b58<\/td>\n<td>\u4fdd\u7559\u9ed8\u8ba4&#xff1b;\u957f\u4f1a\u8bdd &#043; \u9ad8\u4e00\u81f4\u6027\u8981\u6c42\u7684\u6279\u5904\u7406\u573a\u666f\u8bc4\u4f30 localCacheScope&#061;STATEMENT<\/td>\n<\/tr>\n<tr>\n<td>\u4e8c\u7ea7\u7f13\u5b58<\/td>\n<td>\u751f\u4ea7\u4e0d\u5f00\u542f&#xff08;\u4e0d\u5199 &lt;cache\/&gt;&#xff09;&#xff1b;\u4ec5\u63a5\u53d7 namespace \u7c92\u5ea6\u5931\u6548\u7684\u5355\u673a\u53ea\u8bfb\u573a\u666f\u53ef\u4f8b\u5916<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>6.2 \u81ea\u5b9a\u4e49 Cache \u5bf9\u63a5 Redis&#xff1f;<\/h4>\n<p>\u6280\u672f\u4e0a\u53ef\u4ee5\u5b9e\u73b0 org.apache.ibatis.cache.Cache \u63a5\u53e3\u628a\u5b58\u50a8\u6307\u5411 Redis&#xff1a;<\/p>\n<p><span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">RedisCache<\/span> <span class=\"token keyword\">implements<\/span> <span class=\"token class-name\">Cache<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Override<\/span> <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">String<\/span> <span class=\"token function\">getId<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token keyword\">return<\/span> namespaceId<span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Override<\/span> <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">putObject<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Object<\/span> key<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">Object<\/span> value<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token comment\">\/* redis set *\/<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Override<\/span> <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">Object<\/span> <span class=\"token function\">getObject<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Object<\/span> key<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token comment\">\/* redis get *\/<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Override<\/span> <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">Object<\/span> <span class=\"token function\">removeObject<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Object<\/span> key<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token comment\">\/* redis del *\/<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Override<\/span> <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">clear<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token comment\">\/* \u6309 namespace \u524d\u7f00\u5220\u9664 *\/<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ getSize \u7b49\u7701\u7565<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u4f46\u4e0d\u63a8\u8350&#xff0c;\u539f\u56e0&#xff1a;<\/p>\n<li>\u5931\u6548\u7c92\u5ea6\u4ecd\u662f namespace&#xff0c;\u8de8\u8868 JOIN \u7684\u810f\u8bfb\u95ee\u9898\u539f\u6837\u5b58\u5728&#xff1b;<\/li>\n<li>TransactionalCache \u63d0\u4ea4\u540e\u5199\u5165\u4ecd\u5b58\u5728\u300cDB \u5df2\u63d0\u4ea4\u3001\u7f13\u5b58\u672a\u5199\u5165\u300d\u7684\u4e00\u81f4\u6027\u7a97\u53e3&#xff1b;<\/li>\n<li>\u7f13\u5b58\u952e\u7531 MyBatis \u751f\u6210&#xff08;CacheKey&#xff09;&#xff0c;\u65e0\u6cd5\u6309\u4e1a\u52a1\u8bed\u4e49\u7ba1\u7406\u4e0e\u7cbe\u51c6\u5931\u6548\u3002<\/li>\n<h4>6.3 \u63a8\u8350\u6a21\u5f0f&#xff1a;\u5e94\u7528\u5c42\u7f13\u5b58<\/h4>\n<p>\u8bfb\u8def\u5f84&#xff1a;\u5e94\u7528\u4ee3\u7801 \u2192 Spring Cache&#xff08;Caffeine\/Redis&#xff09;\u2192 \u672a\u547d\u4e2d \u2192 MyBatis \u67e5\u8be2 \u2192 \u56de\u586b\u7f13\u5b58<br \/>\n\u5199\u8def\u5f84&#xff1a;\u66f4\u65b0\u6570\u636e\u5e93 \u2192 \u5220\u9664\u5bf9\u5e94\u7f13\u5b58 key&#xff08;Cache-Aside&#xff09;<\/p>\n<p>\u8981\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u5355\u673a\u9ad8\u9891\u8bfb\u7528 Caffeine&#xff08;\u8fdb\u7a0b\u5185\u3001\u7eb3\u79d2\u7ea7&#xff09;&#xff1b;\u8de8\u8282\u70b9\u5171\u4eab\u7528 Redis&#xff1b;<\/li>\n<li>\u5931\u6548\u7b56\u7565\u9996\u9009\u300c\u5148\u66f4\u65b0 DB&#xff0c;\u518d\u5220\u7f13\u5b58\u300d&#xff0c;\u800c\u975e\u66f4\u65b0\u7f13\u5b58&#xff08;\u907f\u514d\u5e76\u53d1\u5199\u8986\u76d6\u4e0e\u65e0\u6548\u8ba1\u7b97&#xff09;&#xff1b;<\/li>\n<li>\u7f13\u5b58 key \u6309\u4e1a\u52a1\u8bed\u4e49\u8bbe\u8ba1&#xff08;\u5982 user:profile:{id}&#xff09;&#xff0c;\u7c92\u5ea6\u53ef\u63a7&#xff1b;<\/li>\n<li>\u4e0e MyBatis \u89e3\u8026&#xff1a;\u7f13\u5b58\u903b\u8f91\u5728 Service \u5c42&#xff0c;\u5207\u6362 ORM \u6846\u67b6\u4e0d\u53d7\u5f71\u54cd\u3002<\/li>\n<\/ul>\n<h4>6.4 \u8ba4\u77e5\u5206\u5c42<\/h4>\n<p>ORM \u5185\u5efa\u7f13\u5b58\u89e3\u51b3\u7684\u662f\u300c\u4f1a\u8bdd\u5185 \/ \u547d\u540d\u7a7a\u95f4\u5185\u300d\u7684\u91cd\u590d\u8bfb\u4f18\u5316&#xff0c;\u4e0d\u89e3\u51b3\u5206\u5e03\u5f0f\u4e00\u81f4\u6027\u3002\u5206\u5e03\u5f0f\u573a\u666f\u7684\u4e00\u81f4\u6027\u8981\u9760\u5916\u90e8\u7f13\u5b58 &#043; \u660e\u786e\u7684\u5931\u6548\u534f\u8bae&#xff08;\u5220\u7f13\u5b58\u3001\u5ef6\u8fdf\u53cc\u5220\u3001binlog \u8ba2\u9605\u7b49&#xff09;\u6765\u4fdd\u8bc1\u2014\u2014\u8fd9\u662f\u7f13\u5b58\u9009\u578b\u7684\u57fa\u672c\u5206\u754c\u7ebf\u3002<\/p>\n<hr \/>\n<h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<li>\u4e24\u7ea7\u7ed3\u6784&#xff1a;\u67e5\u8be2\u987a\u5e8f\u4e3a\u4e8c\u7ea7\u7f13\u5b58&#xff08;namespace \u7ea7&#xff09;\u2192 \u4e00\u7ea7\u7f13\u5b58&#xff08;SqlSession \u7ea7&#xff09;\u2192 \u6570\u636e\u5e93&#xff1b;\u4e00\u7ea7\u9ed8\u8ba4\u5f00\u542f\u3001\u4e8c\u7ea7\u9ed8\u8ba4\u5173\u95ed\u3002<\/li>\n<li>\u4e00\u7ea7\u7f13\u5b58&#xff1a;PerpetualCache \u5b9e\u73b0&#xff0c;CacheKey \u7531 statementId &#043; \u5206\u9875 &#043; SQL &#043; \u53c2\u6570 &#043; environment \u6784\u6210&#xff1b;\u5199\u64cd\u4f5c\/\u63d0\u4ea4\/\u5173\u95ed\u65f6\u6574\u4f53\u6e05\u7a7a&#xff1b;localCacheScope&#061;STATEMENT \u53ef\u7f29\u5c0f\u4f5c\u7528\u57df\u3002<\/li>\n<li>\u4e00\u7ea7\u7f13\u5b58\u7684\u771f\u76f8&#xff1a;Spring \u65e0\u4e8b\u52a1\u6a21\u5f0f\u4e0b\u6bcf\u6b21\u8c03\u7528\u72ec\u7acb SqlSession&#xff0c;\u4e00\u7ea7\u7f13\u5b58\u57fa\u672c\u4e0d\u547d\u4e2d&#xff1b;\u4e8b\u52a1\u5185\u624d\u771f\u6b63\u751f\u6548\u3002<\/li>\n<li>\u4e00\u7ea7\u7f13\u5b58\u810f\u8bfb&#xff1a;\u540c\u4f1a\u8bdd\u5148\u67e5\u540e\u88ab\u4ed6\u4e8b\u52a1\u66f4\u65b0&#xff0c;\u7f13\u5b58\u7ed5\u8fc7\u6570\u636e\u5e93\u5bfc\u81f4\u8bfb\u5230\u65e7\u503c&#xff1b;\u6570\u636e\u5e93\u9694\u79bb\u7ea7\u522b\u65e0\u6cd5\u9632\u5fa1&#xff0c;\u53ea\u80fd\u9760\u7f29\u5c0f\u4f5c\u7528\u57df\u6216\u7f29\u77ed\u4f1a\u8bdd\u751f\u547d\u5468\u671f\u3002<\/li>\n<li>\u4e8c\u7ea7\u7f13\u5b58\u673a\u5236&#xff1a;TransactionalCache \u4fdd\u8bc1\u63d0\u4ea4\u540e\u624d\u5199\u5165&#xff1b;\u5931\u6548\u4ee5 namespace \u4e3a\u5355\u4f4d&#xff08;C\/U\/D \u89e6\u53d1\u5168\u91cf\u6e05\u7a7a&#xff09;\u3002<\/li>\n<li>\u4e8c\u7ea7\u7f13\u5b58\u4e24\u5927\u810f\u8bfb&#xff1a;\u8de8 namespace \u7684 JOIN \u4f9d\u8d56\u5931\u6548\u76f2\u533a&#xff1b;\u591a\u8282\u70b9\u7f13\u5b58\u72ec\u7acb\u65e0\u5931\u6548\u5e7f\u64ad\u3002\u56e0\u6b64\u751f\u4ea7\u73af\u5883\u4e0d\u5efa\u8bae\u5f00\u542f\u3002<\/li>\n<li>\u88c5\u9970\u5668\u67b6\u6784&#xff1a;Cache \u63a5\u53e3\u7ecf PerpetualCache \u2192 \u6dd8\u6c70\u7b56\u7565 \u2192 \u5e8f\u5217\u5316 \u2192 \u65e5\u5fd7 \u2192 \u540c\u6b65 \u2192 \u4e8b\u52a1\u9010\u5c42\u88c5\u9970&#xff0c;\u662f MyBatis \u6269\u5c55\u6027\u8bbe\u8ba1\u7684\u8303\u4f8b\u3002<\/li>\n<li>\u751f\u4ea7\u65b9\u6848&#xff1a;\u5e94\u7528\u5c42 Spring Cache &#043; Caffeine\/Redis&#xff0c;Cache-Aside \u5931\u6548\u7b56\u7565&#xff0c;\u6309\u4e1a\u52a1 key \u7ba1\u7406\u2014\u2014\u628a\u5206\u5e03\u5f0f\u4e00\u81f4\u6027\u95ee\u9898\u653e\u5728\u6b63\u786e\u7684\u5c42\u6b21\u89e3\u51b3\u3002<\/li>\n<hr \/>\n<h3>\u516b\u3001\u5e38\u89c1\u9ad8\u9891\u9762\u8bd5\u9898<\/h3>\n<p>1. MyBatis \u4e00\u7ea7\u7f13\u5b58\u548c\u4e8c\u7ea7\u7f13\u5b58\u7684\u533a\u522b&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;\u4e00\u7ea7\u7f13\u5b58 SqlSession \u7ea7\u3001\u9ed8\u8ba4\u5f00\u542f\u3001PerpetualCache&#xff08;HashMap&#xff09;\u5b9e\u73b0\u3001\u5199\u64cd\u4f5c\/\u63d0\u4ea4\/\u5173\u95ed\u5373\u6e05\u7a7a&#xff1b;\u4e8c\u7ea7\u7f13\u5b58 namespace \u7ea7\u3001\u9700 &lt;cache\/&gt; \u663e\u5f0f\u5f00\u542f\u3001\u8de8 SqlSession \u751f\u6548\u3001TransactionalCache \u4fdd\u8bc1\u63d0\u4ea4\u540e\u5199\u5165\u3001C\/U\/D \u540e\u6309 namespace \u5168\u91cf\u6e05\u7a7a\u3002\u67e5\u8be2\u987a\u5e8f&#xff1a;\u4e8c\u7ea7 \u2192 \u4e00\u7ea7 \u2192 DB\u3002<\/p>\n<p>2. \u4e00\u7ea7\u7f13\u5b58\u7684\u7f13\u5b58\u952e\u5305\u542b\u54ea\u4e9b\u5185\u5bb9&#xff1f;\u4e3a\u4ec0\u4e48\u8fd9\u6837\u8bbe\u8ba1&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;statementId &#043; RowBounds &#043; SQL \u6587\u672c &#043; \u53c2\u6570\u503c &#043; environment id\u3002\u8bbe\u8ba1\u610f\u56fe&#xff1a;\u540c\u65b9\u6cd5\u4e0d\u540c\u53c2\u6570\u9694\u79bb\u3001\u52a8\u6001 SQL \u4e0d\u540c\u7ed3\u6784\u9694\u79bb\u3001\u5206\u9875\u4e0d\u540c\u533a\u95f4\u9694\u79bb&#xff1b;\u4efb\u4e00\u8981\u7d20\u4e0d\u540c\u5373\u4e0d\u540c\u7f13\u5b58\u6761\u76ee\u3002<\/p>\n<p>3. \u4e00\u7ea7\u7f13\u5b58\u6709\u4ec0\u4e48\u810f\u8bfb\u98ce\u9669&#xff1f;\u5982\u4f55\u89c4\u907f&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;\u4f1a\u8bdd A \u67e5\u8be2\u540e&#xff0c;\u6570\u636e\u88ab\u4ed6\u4e8b\u52a1\/\u4f1a\u8bdd\u66f4\u65b0\u5e76\u63d0\u4ea4&#xff0c;A \u518d\u6b21\u67e5\u8be2\u547d\u4e2d\u7f13\u5b58\u8fd4\u56de\u65e7\u503c\u2014\u2014\u7f13\u5b58\u7ed5\u8fc7\u6570\u636e\u5e93&#xff0c;\u9694\u79bb\u7ea7\u522b\u9632\u4e0d\u4f4f\u3002\u89c4\u907f&#xff1a;localCacheScope&#061;STATEMENT\u3001\u7f29\u77ed\u4f1a\u8bdd\u751f\u547d\u5468\u671f&#xff08;Spring \u65e0\u4e8b\u52a1\u6a21\u5f0f\u5929\u7136\u5982\u6b64&#xff09;\u3001\u5173\u952e\u8bed\u53e5 flushCache&#061;\u201ctrue\u201d\u3002<\/p>\n<p>4. \u4e3a\u4ec0\u4e48\u751f\u4ea7\u73af\u5883\u4e0d\u5efa\u8bae\u5f00\u542f MyBatis \u4e8c\u7ea7\u7f13\u5b58&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;\u2460 \u5931\u6548\u7c92\u5ea6\u662f namespace&#xff0c;\u591a\u8868 JOIN \u7684\u67e5\u8be2\u7f13\u5b58\u4e0d\u4f1a\u56e0\u5173\u8054\u8868\u88ab\u4ed6 namespace \u66f4\u65b0\u800c\u5931\u6548&#xff08;\u8de8 namespace \u810f\u8bfb&#xff09;&#xff1b;\u2461 \u7f13\u5b58\u662f JVM \u672c\u5730\u7684&#xff0c;\u591a\u8282\u70b9\u65e0\u5931\u6548\u5e7f\u64ad&#xff1b;\u2462 \u9ed8\u8ba4\u5e8f\u5217\u5316\u526f\u672c\u6709\u5f00\u9500\u3002\u66ff\u4ee3\u65b9\u6848&#xff1a;\u5e94\u7528\u5c42 Caffeine\/Redis &#043; Cache-Aside\u3002<\/p>\n<p>5. \u4e8c\u7ea7\u7f13\u5b58\u7684\u5199\u5165\u65f6\u673a&#xff1f;\u4e3a\u4ec0\u4e48\u8981\u8fd9\u6837\u8bbe\u8ba1&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;\u4e8b\u52a1\u63d0\u4ea4&#xff08;\u6216\u4f1a\u8bdd\u5173\u95ed&#xff09;\u540e\u7531 TransactionalCache \u63d0\u4ea4\u5199\u5165\u3002\u76ee\u7684&#xff1a;\u9632\u6b62\u672a\u63d0\u4ea4\u6570\u636e\u8fdb\u5165\u7f13\u5b58\u88ab\u5176\u4ed6\u4f1a\u8bdd\u8bfb\u5230&#xff08;\u810f\u6570\u636e\u5165\u7f13\u5b58&#xff09;\u3002<\/p>\n<p>6. Spring \u6574\u5408\u540e\u4e00\u7ea7\u7f13\u5b58\u8fd8\u6709\u6548\u5417&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;\u53d6\u51b3\u4e8e\u4e8b\u52a1\u3002\u65e0\u4e8b\u52a1\u65f6 SqlSessionTemplate \u6bcf\u6b21\u8c03\u7528\u521b\u5efa\u72ec\u7acb SqlSession&#xff0c;\u4f1a\u8bdd\u95f4\u4e0d\u5171\u4eab\u4e00\u7ea7\u7f13\u5b58&#xff0c;\u57fa\u672c\u4e0d\u547d\u4e2d&#xff1b;\u540c\u4e00 &#064;Transactional \u5185\u5171\u4eab SqlSession&#xff0c;\u4e00\u7ea7\u7f13\u5b58\u751f\u6548&#xff0c;\u4e14\u4e8b\u52a1\u5185\u5199\u64cd\u4f5c\u4f1a\u6e05\u7a7a\u7f13\u5b58\u3002<\/p>\n<p>7. readOnly \u5c5e\u6027\u7684\u4f5c\u7528&#xff1f;true \u548c false \u7684\u533a\u522b&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;false&#xff08;\u9ed8\u8ba4&#xff09;\u5b58\u53d6\u5e8f\u5217\u5316\u526f\u672c&#xff0c;\u5404\u8c03\u7528\u65b9\u62ff\u5230\u72ec\u7acb\u5bf9\u8c61&#xff0c;\u5b89\u5168\u4f46\u6709\u6027\u80fd\u5f00\u9500&#xff0c;\u5b9e\u4f53\u9700 Serializable&#xff1b;true \u76f4\u63a5\u8fd4\u56de\u7f13\u5b58\u4e2d\u5bf9\u8c61\u5f15\u7528&#xff0c;\u6027\u80fd\u597d&#xff0c;\u4f46\u8c03\u7528\u65b9\u4fee\u6539\u8fd4\u56de\u503c\u4f1a\u6c61\u67d3\u7f13\u5b58&#xff0c;\u53ea\u9002\u5408\u4e25\u683c\u53ea\u8bfb\u7684\u6570\u636e\u3002<\/p>\n<p>8. MyBatis \u7f13\u5b58\u4e0e Redis \u7f13\u5b58\u5982\u4f55\u53d6\u820d&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;MyBatis \u5185\u5efa\u7f13\u5b58\u662f\u4f1a\u8bdd\/namespace \u7c92\u5ea6\u7684\u8fdb\u7a0b\u5185\u4f18\u5316&#xff0c;\u89e3\u51b3\u91cd\u590d\u8bfb&#xff0c;\u4e0d\u89e3\u51b3\u5206\u5e03\u5f0f\u4e00\u81f4\u6027&#xff1b;Redis \u662f\u5206\u5e03\u5f0f\u5171\u4eab\u7f13\u5b58&#xff0c;\u53ef\u6309\u4e1a\u52a1 key \u7cbe\u51c6\u5931\u6548\u3001\u652f\u6301\u96c6\u7fa4\u3002\u751f\u4ea7\u505a\u6cd5&#xff1a;\u5173\u95ed\u4e8c\u7ea7\u7f13\u5b58&#xff0c;\u7528 Spring Cache \u62bd\u8c61\u7edf\u4e00\u63a5\u5165 Caffeine&#xff08;\u5355\u673a\u70ed\u70b9&#xff09;\u6216 Redis&#xff08;\u5171\u4eab&#xff09;&#xff0c;\u5199\u64cd\u4f5c\u91c7\u7528\u5148\u66f4\u65b0 DB \u518d\u5220\u7f13\u5b58\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260918014901-6aac988d2107d.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MyBatis \u7f13\u5b58\u673a\u5236\u8be6\u89e3 \u5b9a\u4f4d&#xff1a;MyBatis \u7cfb\u5217\u7b2c 4 \u7bc7\u2014\u2014\u4e00\u7ea7\u7f13\u5b58\u4e0e\u4e8c\u7ea7\u7f13\u5b58\u7684\u5b8c\u6574\u673a\u5236\u3001\u810f\u8bfb\u5206\u6790\u4e0e\u751f\u4ea7\u5b9e\u8df5\u7ed3\u8bba \u9002\u7528\u7248\u672c&#xff1a;MyBatis 3.5.x&#xff08;JDK 8&#xff09; \u76ee\u5f55<br \/>\n\u7f13\u5b58\u5168\u666f\u4e00\u7ea7\u7f13\u5b58&#xff08;Local Cache&#xff09;\u4e00\u7ea7\u7f13\u5b58\u810f\u8bfb\u5206\u6790\u4e8c\u7ea7\u7f13\u5b58&#xff08;Global Cache&#xff09;\u7f13\u5b58\u6267\u884c\u987a\u5e8f\u4e0e\u88c5\u9970\u7ed3\u6784\u751f\u4ea7\u5b9e\u8df5\u4e0e\u5916\u90e8\u7f13\u5b58\u6574\u5408\u603b\u7ed3\u5e38\u89c1\u9ad8\u9891\u9762\u8bd5\u9898 \u4e00\u3001\u7f13\u5b58\u5168\u666f<br \/>\nMyBat<\/p>\n","protected":false},"author":2,"featured_media":106766,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1769,188],"topic":[],"class_list":["post-106767","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-mybatis","tag-188"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>MyBatis \u7f13\u5b58\u673a\u5236\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/106767.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MyBatis \u7f13\u5b58\u673a\u5236\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"MyBatis \u7f13\u5b58\u673a\u5236\u8be6\u89e3 \u5b9a\u4f4d&#xff1a;MyBatis \u7cfb\u5217\u7b2c 4 \u7bc7\u2014\u2014\u4e00\u7ea7\u7f13\u5b58\u4e0e\u4e8c\u7ea7\u7f13\u5b58\u7684\u5b8c\u6574\u673a\u5236\u3001\u810f\u8bfb\u5206\u6790\u4e0e\u751f\u4ea7\u5b9e\u8df5\u7ed3\u8bba \u9002\u7528\u7248\u672c&#xff1a;MyBatis 3.5.x&#xff08;JDK 8&#xff09; \u76ee\u5f55 \u7f13\u5b58\u5168\u666f\u4e00\u7ea7\u7f13\u5b58&#xff08;Local Cache&#xff09;\u4e00\u7ea7\u7f13\u5b58\u810f\u8bfb\u5206\u6790\u4e8c\u7ea7\u7f13\u5b58&#xff08;Global Cache&#xff09;\u7f13\u5b58\u6267\u884c\u987a\u5e8f\u4e0e\u88c5\u9970\u7ed3\u6784\u751f\u4ea7\u5b9e\u8df5\u4e0e\u5916\u90e8\u7f13\u5b58\u6574\u5408\u603b\u7ed3\u5e38\u89c1\u9ad8\u9891\u9762\u8bd5\u9898 \u4e00\u3001\u7f13\u5b58\u5168\u666f MyBat\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/106767.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-18T01:49:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260918014901-6aac988d2107d.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/106767.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/106767.html\",\"name\":\"MyBatis \u7f13\u5b58\u673a\u5236\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-18T01:49:02+00:00\",\"dateModified\":\"2026-09-18T01:49:02+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/106767.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/106767.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/106767.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MyBatis \u7f13\u5b58\u673a\u5236\u8be6\u89e3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MyBatis \u7f13\u5b58\u673a\u5236\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/106767.html","og_locale":"zh_CN","og_type":"article","og_title":"MyBatis \u7f13\u5b58\u673a\u5236\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"MyBatis \u7f13\u5b58\u673a\u5236\u8be6\u89e3 \u5b9a\u4f4d&#xff1a;MyBatis \u7cfb\u5217\u7b2c 4 \u7bc7\u2014\u2014\u4e00\u7ea7\u7f13\u5b58\u4e0e\u4e8c\u7ea7\u7f13\u5b58\u7684\u5b8c\u6574\u673a\u5236\u3001\u810f\u8bfb\u5206\u6790\u4e0e\u751f\u4ea7\u5b9e\u8df5\u7ed3\u8bba \u9002\u7528\u7248\u672c&#xff1a;MyBatis 3.5.x&#xff08;JDK 8&#xff09; \u76ee\u5f55 \u7f13\u5b58\u5168\u666f\u4e00\u7ea7\u7f13\u5b58&#xff08;Local Cache&#xff09;\u4e00\u7ea7\u7f13\u5b58\u810f\u8bfb\u5206\u6790\u4e8c\u7ea7\u7f13\u5b58&#xff08;Global Cache&#xff09;\u7f13\u5b58\u6267\u884c\u987a\u5e8f\u4e0e\u88c5\u9970\u7ed3\u6784\u751f\u4ea7\u5b9e\u8df5\u4e0e\u5916\u90e8\u7f13\u5b58\u6574\u5408\u603b\u7ed3\u5e38\u89c1\u9ad8\u9891\u9762\u8bd5\u9898 \u4e00\u3001\u7f13\u5b58\u5168\u666f MyBat","og_url":"https:\/\/www.wsisp.com\/helps\/106767.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-18T01:49:02+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260918014901-6aac988d2107d.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/106767.html","url":"https:\/\/www.wsisp.com\/helps\/106767.html","name":"MyBatis \u7f13\u5b58\u673a\u5236\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-18T01:49:02+00:00","dateModified":"2026-09-18T01:49:02+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/106767.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/106767.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/106767.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"MyBatis \u7f13\u5b58\u673a\u5236\u8be6\u89e3"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/106767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=106767"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/106767\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/106766"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=106767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=106767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=106767"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=106767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}