{"id":157,"date":"2020-07-28T21:01:47","date_gmt":"2020-07-28T13:01:47","guid":{"rendered":"http:\/\/121.89.208.222\/?p=157"},"modified":"2020-12-10T14:24:25","modified_gmt":"2020-12-10T06:24:25","slug":"157","status":"publish","type":"post","link":"http:\/\/moyisuiying.com\/index.php\/mybatis\/157.html","title":{"rendered":"\u57fa\u4e8e\u6ce8\u89e3\u914d\u7f6e\u7684Mybatis\u7684\u589e\u5220\u67e5\u6539"},"content":{"rendered":"\n<p>1.\u5728\u4e0a\u7bc7\u535a\u5ba2\u4e2d\u4ecb\u7ecd\u4e86<a href=\"http:\/\/moyisuiying.com\/index.php\/mybatis\/148.html\">\u57fa\u4e8eXML\u914d\u7f6e\u7684Mybatis\u7684\u589e\u5220\u67e5\u6539<\/a>\u7684\u5177\u4f53\u5b9e\u73b0\uff0c\u6b64\u6b21\u4fbf\u5b9e\u73b0\u57fa\u4e8e\u6ce8\u89e3\u5b9e\u73b0mybatis\u7684\u589e\u5220\u67e5\u6539\u529f\u80fd\u3002\u5728\u4e0a\u7bc7\u535a\u5ba2<a href=\"http:\/\/moyisuiying.com\/index.php\/mybatis\/148.html\">\u57fa\u4e8eXML\u914d\u7f6e\u7684Mybatis\u7684\u589e\u5220\u67e5\u6539<\/a>\u7684\u6e90\u7801\u4ee5\u53ca\u914d\u7f6e\u4e4b\u4e0b\u7ee7\u7eed\u6dfb\u52a0\u6ce8\u89e3\u7684\u5b9e\u73b0\u3002<br>2.\u9996\u5148\u4fee\u6539mybatis-config.xml\u914d\u7f6e\u6587\u4ef6\uff0c\u5c06UserDao\u7684\u6620\u5c04\u914d\u7f6e\u4fe1\u606f\u6539\u4e3a\u5982\u4e0b\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  &lt;mappers>\n        &lt;!--  \u6307\u5b9aUserdao\u7684\u4f4d\u7f6e-->\n&lt;!--        \u4f7f\u7528\u6ce8\u89e3\uff0c\u6307\u5b9aUserDao\u7684\u5168\u9650\u5b9a\u7c7b\u540d -->\n        &lt;mapper class=\"dao.UserDao\">&lt;\/mapper>\n    &lt;\/mappers><\/code><\/pre>\n\n\n\n<p>2.\u5728UserDao.java\u4e2d\u6bcf\u4e2a\u65b9\u6cd5\u5bf9\u5e94\u6dfb\u52a0mybatis\u7684\u6ce8\u89e3\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>package <\/strong>dao;\n\n<strong>import <\/strong>entity.User;\n<strong>import <\/strong>org.apache.ibatis.annotations.Delete;\n<strong>import <\/strong>org.apache.ibatis.annotations.Insert;\n<strong>import <\/strong>org.apache.ibatis.annotations.Select;\n<strong>import <\/strong>org.apache.ibatis.annotations.Update;\n\n<strong>import <\/strong>java.util.List;\n\n<em>\/**\n * Classname:mybatisdemo\n * <\/em><strong><em>@description:User\u7684dao\u63a5\u53e3\n <\/em><\/strong><em>* <\/em><strong><em>@author: <\/em><\/strong><em>\u964c\u610f\u968f\u5f71\n * <\/em><strong><em>@Date: <\/em><\/strong><em>2020-07-24 10:35\n *\/\n<\/em><strong>public interface <\/strong>UserDao <strong><em>{\n <\/em><\/strong><em>\/**\n * <\/em><strong><em>@date: <\/em><\/strong><em>2020\/7\/24 0024 10:41\n * <\/em><strong><em>@description:\u83b7\u53d6\u6240\u6709\u7684\u7528\u6237\u4fe1\u606f\n <\/em><\/strong><em>* <\/em><strong><em>@return: <\/em><\/strong><em>\u8fd4\u56de\u5305\u542b\u6240\u6709\u7684\u7528\u6237\u7684list\n *\/\n <\/em>@Select<strong><em>(<\/em>\"select* from user\"<em>)\n <\/em>public <\/strong>List<strong><em>&lt;<\/em><\/strong>User<strong><em>&gt; <\/em><\/strong>getAll<strong><em>()<\/em><\/strong>;\n<em>\/**\n * <\/em><strong><em>@Description <\/em><\/strong><em>:\u5411\u6570\u636e\u5e93\u4e2d\u63d2\u5165\u65b0\u7684\u7528\u6237\u4fdd\u5b58\n * <\/em><strong><em>@Date <\/em><\/strong><em>12:34 2020\/7\/28 0028\n * <\/em><strong><em>@Param <\/em><\/strong><em>* @param user \uff1a\u9700\u8981\u5904\u5165\u7684\u7528\u6237\n * <\/em><strong><em>@return <\/em><\/strong><em>void\n **\/\n <\/em>@Insert<strong><em>(<\/em>\"insert into user(name,password,age,createTime) values(#{name},#{password},#{age},#{createTime});\"<em>)\n <\/em>public void <\/strong>saveUser<strong><em>(<\/em><\/strong>User user<strong><em>)<\/em><\/strong>;\n<em>\/**\n * <\/em><strong><em>@Description <\/em><\/strong><em>:\u6839\u636e\u4e3b\u952eid\u4ece\u6570\u636e\u5e93\u4e2d\u5220\u9664\u7528\u6237\n * <\/em><strong><em>@Date <\/em><\/strong><em>12:58 2020\/7\/28 0028\n * <\/em><strong><em>@Param <\/em><\/strong><em>* @param id \uff1aUser\u7684\u4e3b\u952eid\n * <\/em><strong><em>@return <\/em><\/strong><em>void\n **\/\n <\/em>@Delete<strong><em>(<\/em>\"delete from user where id=#{id}\"<em>)\n <\/em>public void <\/strong>deleteUser<strong><em>(<\/em>int <\/strong>id<strong><em>)<\/em><\/strong>;\n<em>\/**\n * <\/em><strong><em>@Description <\/em><\/strong><em>:\u66f4\u65b0\u7528\u6237\u4fe1\u606f\n * <\/em><strong><em>@Date <\/em><\/strong><em>13:08 2020\/7\/28 0028\n * <\/em><strong><em>@Param <\/em><\/strong><em>* @param user \uff1a\u65b0\u7684\u7528\u6237\n * <\/em><strong><em>@return <\/em><\/strong><em>void\n **\/\n <\/em>@Update<em>(<\/em>\" update user set name=#{name},password=#{password},age=#{age},createTime=#{createTime} where id=#{id}\"<em>)\n <\/em>public void updateUser<strong><em>(<\/em><\/strong>User user<strong><em>)<\/em><\/strong>;\n\/**\n * <strong>@Description <\/strong>:\u901a\u8fc7\u4e3b\u952eid\u67e5\u627e\u7528\u6237\n * <strong>@Date <\/strong>13:17 2020\/7\/28 0028\n * <strong>@Param <\/strong>* @param id \uff1a\n * <strong>@return <\/strong>entity.User\n **\/\n @Select<strong><em>(<\/em>\"select * from User where id=#{id}\"<em>)\n <\/em>public <\/strong>User findUser<strong><em>(<\/em>int <\/strong>id<strong><em>)<\/em><\/strong>;\n\n<strong><em>}<\/em><\/strong><\/pre>\n\n\n\n<p>3.\u6d4b\u8bd5\u622a\u56fe<br>3.1\u6d4b\u8bd5testSaveUser\u65b9\u6cd5<br><img  src=\"https:\/\/img-blog.csdnimg.cn\/202007282048538.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200728204913107.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>3.2\u6d4b\u8bd5testDeleteUser\u65b9\u6cd5\u622a\u56fe<br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200728205029557.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200728205053201.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>3.3\u6d4b\u8bd5testFindUser\u65b9\u6cd5\u622a\u56fe<br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200728205202937.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200728205210486.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>3.4\u6d4b\u8bd5testUpdateUser\u622a\u56fe<br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200728205321938.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200728205342206.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>4.\u6d4b\u8bd5\u7684\u76ee\u5f55\u7ed3\u6784<br><img  class=\"lazyload\" data-src=\"https:\/\/img-blog.csdnimg.cn\/20200728205527724.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><strong>\u672c\u6b21\u6d4b\u8bd5\u9879\u76ee\u7684\u6e90\u7801\u5df2\u7ecf\u4e0a\u4f20\u5230\u6211\u7684\u4e2a\u4eba\u535a\u5ba2\uff0c\u9700\u8981\u7684\u81ea\u884c\u4e0b\u8f7d\uff08\u4e0b\u8f7d\u89e3\u538b\u540e\u5bfc\u5165idea\u5373\u53ef\uff09<\/strong>\uff1a<a href=\"http:\/\/moyisuiying.com\/wp-content\/uploads\/2020\/07\/mybatisdemo3.rar\">http:\/\/moyisuiying.com\/wp-content\/uploads\/2020\/07\/mybatisdemo3.rar<\/a><\/p >\n<noscript><img src=\"https:\/\/img-blog.csdnimg.cn\/202007282048538.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200728204913107.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>3.2\u6d4b\u8bd5testDeleteUser\u65b9\u6cd5\u622a\u56fe<br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200728205029557.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200728205053201.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>3.3\u6d4b\u8bd5testFindUser\u65b9\u6cd5\u622a\u56fe<br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200728205202937.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200728205210486.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>3.4\u6d4b\u8bd5testUpdateUser\u622a\u56fe<br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200728205321938.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200728205342206.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>4.\u6d4b\u8bd5\u7684\u76ee\u5f55\u7ed3\u6784<br><img src=\"https:\/\/img-blog.csdnimg.cn\/20200728205527724.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br><strong>\u672c\u6b21\u6d4b\u8bd5\u9879\u76ee\u7684\u6e90\u7801\u5df2\u7ecf\u4e0a\u4f20\u5230\u6211\u7684\u4e2a\u4eba\u535a\u5ba2\uff0c\u9700\u8981\u7684\u81ea\u884c\u4e0b\u8f7d\uff08\u4e0b\u8f7d\u89e3\u538b\u540e\u5bfc\u5165idea\u5373\u53ef\uff09<\/strong>\uff1a<a href=\"http:\/\/moyisuiying.com\/wp-content\/uploads\/2020\/07\/mybatisdemo3.rar\">http:\/\/moyisuiying.com\/wp-content\/uploads\/2020\/07\/mybatisdemo3.rar<\/a><\/p><\/noscript>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u6ce8\u89e3\u5b9e\u73b0mybatis\u7684\u589e\u5220\u67e5\u6539\u529f\u80fd<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[11,13,24,25],"_links":{"self":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts\/157"}],"collection":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/comments?post=157"}],"version-history":[{"count":2,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts\/157\/revisions"}],"predecessor-version":[{"id":215,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts\/157\/revisions\/215"}],"wp:attachment":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/media?parent=157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/categories?post=157"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/tags?post=157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}