
{"id":2810,"date":"2020-12-21T10:42:05","date_gmt":"2020-12-21T02:42:05","guid":{"rendered":"http:\/\/127.0.0.2\/?p=2810"},"modified":"2020-12-21T10:42:05","modified_gmt":"2020-12-21T02:42:05","slug":"2020java%e6%a1%86%e6%9e%b6%e6%95%99%e7%a8%8b%e4%b9%8bmybatis%e7%bc%93%e5%ad%98","status":"publish","type":"post","link":"https:\/\/www.9713job.com\/?p=2810","title":{"rendered":"2020java\u6846\u67b6\u6559\u7a0b\u4e4bmybatis\u7f13\u5b58"},"content":{"rendered":"<h3>2020java\u6846\u67b6\u6559\u7a0b\u4e4bmybatis\u7f13\u5b58<\/h3>\n<h3>\u4e00\u7ea7\u7f13\u5b58\uff1a<\/h3>\n<p>\u662fsession\u7ea7\u522b\u7684\u7f13\u5b58\uff0c\u4e00\u7ea7\u7f13\u5b58\u9ed8\u8ba4\u5b58\u5728\u3002<br \/>\n\u5f53\u5728\u540c\u4e00\u4e2asession\u8303\u56f4\u6267\u884c\u67e5\u8be2\u7684\u65f6\u5019\uff0c\u5982\u679c\u6267\u884c\u76f8\u540c\u7684\u67e5\u8be2\uff0c\u90a3\u4e48\u7b2c\u4e8c\u6b21\u67e5\u8be2\u4f1a\u4ece\u7f13\u5b58\u4e2d\u83b7\u53d6\u6570\u636e<\/p>\n<p><strong>\u6d4b\u8bd51\uff1a<\/strong><\/p>\n<pre>@Test\r\npublic void testSelectUsersCacheLevelOne1(){\r\n    SqlSession ss = MybatisUtils.getSqlSession();\r\n    UsersMapper um = ss.getMapper(UsersMapper.class);\r\n    Users users1 = um.selectByPrimaryKey(1);\r\n    System.out.println(\"\u7ed3\u679c\u5df2\u67e5\u8be2\");\r\n    Users users2 = um.selectByPrimaryKey(1);\r\n    System.out.println(\"\u7ed3\u679c\u5df2\u67e5\u8be2\uff1a\u4ece\u7f13\u5b58\u4e2d\u83b7\u53d6\u6570\u636e\");\r\n    ss.close();\r\n    System.out.println(\"session\u5173\u95ed\");\r\n}<\/pre>\n<p><!--more--><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/21\/1.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/21\/2.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>\u6d4b\u8bd52\uff1a<\/strong><\/p>\n<p>\u5982\u679c\u4e24\u6b21\u67e5\u8be2\u4e4b\u95f4\u6709\u589e\u5220\u6539\u64cd\u4f5c\uff0csqlsession\u7f13\u5b58\u533a\u4f1a\u88ab\u81ea\u52a8\u6e05\u7a7a\uff0c\u4e0b\u4e00\u6b21\u67e5\u8be2\u4f1a\u91cd\u65b0\u6267\u884csql\u8bed\u53e5<\/p>\n<pre>@Test\r\npublic void testSelectUsersCacheLevelOne2(){\r\n    SqlSession ss = MybatisUtils.getSqlSession();\r\n    UsersMapper um = ss.getMapper(UsersMapper.class);\r\n    Users users1 = um.selectByPrimaryKey(1);\r\n    System.out.println(\"\u7ed3\u679c\u5df2\u67e5\u8be2\");\r\n    users1.setMobile(\"888\");\r\n    um.updateByPrimaryKey(users1);\r\n    System.out.println(\"\u5237\u65b0\u7f13\u5b58\");\r\n    Users users2 = um.selectByPrimaryKey(1);\r\n    System.out.println(\"\u91cd\u65b0\u6267\u884c\u67e5\u8be2\");\r\n    ss.commit();\r\n    ss.close();\r\n    System.out.println(\"session\u5173\u95ed\");\r\n}<\/pre>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/21\/3.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/21\/4.png\" alt=\"\" width=\"680\" \/><\/p>\n<hr \/>\n<h3>\u4e8c\u7ea7\u7f13\u5b58<\/h3>\n<p>\u9ed8\u8ba4\u4e0d\u5f00\u542f\uff0c\u5728\u4e0d\u540c\u7684session\u8303\u56f4\u5185\uff0c\u6267\u884c\u76f8\u540c\u7684\u6570\u636e\u67e5\u8be2\uff0c\u6bcf\u6b21\u67e5\u8be2\u5c06\u4f1a\u6267\u884c\u72ec\u7acb\u7684\u6570\u636e\u5e93\u68c0\u7d22\u8fc7\u7a0b\u3002<\/p>\n<p><strong>\u6d4b\u8bd51\uff1a<\/strong><\/p>\n<pre>@Test\r\npublic void testSelectUsersCacheLevelTwo1(){\r\n    SqlSession ss1 = MybatisUtils.getSqlSession();\r\n    UsersMapper um1 = ss1.getMapper(UsersMapper.class);\r\n    Users users1 = um1.selectByPrimaryKey(1);\r\n    System.out.println(\"\u7ed3\u679c\u5df2\u67e5\u8be2\");\r\n    ss1.close();\r\n    SqlSession ss2 = MybatisUtils.getSqlSession();\r\n    UsersMapper um2 = ss2.getMapper(UsersMapper.class);\r\n    Users users2 = um2.selectByPrimaryKey(1);\r\n    System.out.println(\"\u7ed3\u679c\u5df2\u67e5\u8be2:\u91cd\u65b0\u67e5\u8be2\u6570\u636e\u5e93\");\r\n    ss2.close();\r\n    System.out.println(\"session\u5173\u95ed\");\r\n}<\/pre>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/21\/5.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/21\/6.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>\u5f00\u542f\u4e8c\u7ea7\u7f13\u5b58\uff1a<\/p>\n<p>1.\u5728UsersMapper.xml\u6dfb\u52a0 &lt;cache\/&gt;<br \/>\n2.\u5728\u5b9e\u4f53\u7c7b\u4e2d\u5b9e\u73b0\u5e8f\u5217\u5316Serializable\u63a5\u53e3<\/p>\n<p><strong>\u6d4b\u8bd52\uff1a<\/strong><\/p>\n<pre>@Test\r\npublic void testSelectUsersCacheLevelTwo2(){\r\n    SqlSession ss1 = MybatisUtils.getSqlSession();\r\n    UsersMapper um1 = ss1.getMapper(UsersMapper.class);\r\n    Users users1 = um1.selectByPrimaryKey(1);\r\n    System.out.println(\"\u7ed3\u679c\u5df2\u67e5\u8be2\");\r\n    ss1.close();\r\n    SqlSession ss2 = MybatisUtils.getSqlSession();\r\n    UsersMapper um2 = ss2.getMapper(UsersMapper.class);\r\n    Users users2 = um2.selectByPrimaryKey(1);\r\n    System.out.println(\"\u7ed3\u679c\u5df2\u67e5\u8be2:\u4ece\u7f13\u5b58\u4e2d\u83b7\u53d6\u6570\u636e\uff0c\u7f13\u5b58\u547d\u4e2d\u7387\u662f0.5\");\r\n    ss2.close();\r\n    System.out.println(\"session\u5173\u95ed\");\r\n}<\/pre>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/21\/7.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/21\/8.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>\u6d4b\u8bd53\uff1a<\/strong><\/p>\n<p>\u5982\u679c\u5f00\u542f\u4e86\u4e8c\u7ea7\u7f13\u5b58\uff0c\u548c\u4e00\u7ea7\u7f13\u5b58\u76f8\u540c\uff0c\u5982\u679c\u4e24\u6b21\u67e5\u8be2\u4e4b\u95f4\u6709\u589e\u5220\u6539\u64cd\u4f5c\uff0c\u4e8c\u7ea7\u7f13\u5b58\u533a\u4f1a\u88ab\u81ea\u52a8\u6e05\u7a7a\uff0c\u4e0b\u4e00\u6b21\u67e5\u8be2\u4f1a\u91cd\u65b0\u6267\u884csql\u8bed\u53e5<\/p>\n<pre>@Test\r\npublic void testSelectUsersCacheLevelTwo3(){\r\n    SqlSession ss1 = MybatisUtils.getSqlSession();\r\n    UsersMapper um1 = ss1.getMapper(UsersMapper.class);\r\n    Users users1 = um1.selectByPrimaryKey(1);\r\n    System.out.println(\"\u7ed3\u679c\u5df2\u67e5\u8be2\");\r\n    users1.setMobile(\"888\");\r\n    um1.updateByPrimaryKey(users1);\r\n    System.out.println(\"\u5237\u65b0\u7f13\u5b58\");\r\n    ss1.commit();ss1.close();\r\n    SqlSession ss2 = MybatisUtils.getSqlSession();\r\n    UsersMapper um2 = ss2.getMapper(UsersMapper.class);\r\n    Users users2 = um2.selectByPrimaryKey(1);\r\n    System.out.println(\"\u7ed3\u679c\u5df2\u67e5\u8be2\u3002\u7f13\u5b58\u88ab\u5237\u65b0\uff0c\u91cd\u65b0\u67e5\u8be2\");\r\n    ss2.close();\r\n    System.out.println(\"session\u5173\u95ed\");\r\n}<\/pre>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/21\/9.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/21\/10.png\" alt=\"\" width=\"680\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>2020java\u6846\u67b6\u6559\u7a0b\u4e4bmybatis\u7f13\u5b58 \u4e00\u7ea7\u7f13\u5b58\uff1a \u662fsession\u7ea7\u522b\u7684\u7f13\u5b58\uff0c\u4e00\u7ea7\u7f13\u5b58\u9ed8\u8ba4\u5b58\u5728\u3002 \u5f53\u5728 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2810","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2810"}],"version-history":[{"count":7,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2810\/revisions"}],"predecessor-version":[{"id":2817,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2810\/revisions\/2817"}],"wp:attachment":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}