{"id":69103,"date":"2026-01-31T05:05:06","date_gmt":"2026-01-30T21:05:06","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/69103.html"},"modified":"2026-01-31T05:05:06","modified_gmt":"2026-01-30T21:05:06","slug":"day-8-mybatis","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/69103.html","title":{"rendered":"day-8 MyBatis"},"content":{"rendered":"<h2>MyBatis<\/h2>\n<h3>\u4e00\u3001\u81ea\u589e ID \u63d2\u5165\u89c4\u5219<\/h3>\n<li>\u6570\u636e\u5e93\u5b57\u6bb5\u8bbe\u4e3a\u81ea\u589e&#xff08;\u5982 MySQL AUTO_INCREMENT&#xff09;&#xff0c;INSERT \u8bed\u53e5\u7701\u7565\u81ea\u589e\u5b57\u6bb5&#xff0c;\u6570\u636e\u5e93\u81ea\u52a8\u751f\u6210 ID&#xff1b;<\/li>\n<li>\u5b9e\u4f53\u7c7b\u4e2d\u81ea\u589e\u5b57\u6bb5\u65e0\u9700\u8d4b\u503c&#xff08;\u9ed8\u8ba4 null \u5373\u53ef&#xff09;&#xff0c;MyBatis \u53ef\u901a\u8fc7&#064;Options(useGeneratedKeys &#061; true, keyProperty &#061; &#034;id&#034;)\u5c06\u751f\u6210\u7684 ID \u56de\u663e\u5230\u5b9e\u4f53&#xff1b;<\/li>\n<li>\u7981\u6b62\u4f20 0\/-1 \u7b49\u975e null \u65e0\u6548\u503c&#xff0c;\u4f1a\u76f4\u63a5\u63d2\u5165\u8be5\u503c\u5bfc\u81f4\u4e3b\u952e\u6df7\u4e71\u3002<\/li>\n<h3>\u4e8c\u3001SQL \u5360\u4f4d\u7b26\u6838\u5fc3\u89c4\u8303<\/h3>\n<h4>1. \u4f18\u5148\u4f7f\u7528#{}&#xff08;\u9884\u7f16\u8bd1\u5360\u4f4d\u7b26&#xff09;<\/h4>\n<ul>\n<li>\u5929\u7136\u9632\u6b62 SQL \u6ce8\u5165&#xff0c;\u81ea\u52a8\u505a\u7c7b\u578b\u8f6c\u6362\u3001\u52a0\u5f15\u53f7&#xff0c;\u662f\u5f00\u53d1\u9ed8\u8ba4\u9009\u62e9&#xff1b;<\/li>\n<li>\u7edd\u5bf9\u7981\u6b62 Java \u4ee3\u7801\u4e2d\u7528&#043;\u53f7\u62fc\u63a5 SQL \u53c2\u6570&#xff0c;\u5b58\u5728\u4e25\u91cd\u6ce8\u5165\u98ce\u9669\u3002<\/li>\n<\/ul>\n<h4>2. \u7279\u6b8a\u573a\u666f\u4f7f\u7528${}&#xff08;\u5b57\u7b26\u4e32\u62fc\u63a5&#xff09;<\/h4>\n<ul>\n<li>\u4ec5\u7528\u4e8eSQL \u6807\u8bc6\u7b26 \/ \u5173\u952e\u5b57\u52a8\u6001\u66ff\u6362&#xff08;\u8868\u540d\u3001\u5217\u540d\u3001\u6392\u5e8f\u5b57\u6bb5 \/ \u65b9\u5f0f&#xff09;&#xff0c;\u5982order by ${sortField} ${sortType}&#xff1b;<\/li>\n<li>\u5fc5\u987b\u505a\u767d\u540d\u5355\u6821\u9a8c&#xff08;\u4ec5\u5141\u8bb8\u5408\u6cd5\u503c\u4f20\u5165&#xff09;&#xff0c;\u7981\u6b62\u76f4\u63a5\u63a5\u6536\u524d\u7aef\u539f\u59cb\u8f93\u5165&#xff0c;\u907f\u514d\u6ce8\u5165\u3002<\/li>\n<\/ul>\n<h4>3. AS \u522b\u540d\u4f7f\u7528\u539f\u5219<\/h4>\n<ul>\n<li>\u666e\u901a\u5355\u8868 CRUD\u65e0\u9700\u4f7f\u7528&#xff0c;\u67e5\u539f\u751f\u5b57\u6bb5&#xff0c;\u540e\u7aef \/ \u524d\u7aef\u505a\u5b57\u6bb5\u9002\u914d&#xff0c;\u7b26\u5408\u5206\u5c42\u8bbe\u8ba1&#xff1b;<\/li>\n<li>\u5fc5\u987b\u4f7f\u7528\u573a\u666f&#xff1a;\u805a\u5408\u67e5\u8be2&#xff08;count(*) as total&#xff09;\u3001\u8054\u8868\u67e5\u8be2&#xff08;\u89e3\u51b3\u5b57\u6bb5\u91cd\u540d&#xff09;\u3001\u590d\u6742\u5b50\u67e5\u8be2&#xff08;\u5916\u5c42\u9700\u5f15\u7528\u5185\u5c42\u7ed3\u679c&#xff09;\u3002<\/li>\n<\/ul>\n<h3>\u4e09\u3001MyBatis \u6838\u5fc3\u4f20\u53c2\u89c4\u5219&#xff08;\u65e0 &#064;Param&#xff09;<\/h3>\n<h4>1. \u4f20\u5355\u4e2a\u5b9e\u4f53\u7c7b\u5bf9\u8c61&#xff08;\u6700\u5e38\u7528&#xff09;<\/h4>\n<ul>\n<li>#{\u5360\u4f4d\u7b26\u540d} \u5fc5\u987b\u4e0e\u5b9e\u4f53\u7c7b\u5c5e\u6027\u540d\u4e25\u683c\u4e00\u81f4&#xff08;MyBatis \u901a\u8fc7 getter\/setter \u53d6\u503c&#xff0c;\u533a\u5206\u5927\u5c0f\u5199&#xff09;&#xff1b;<\/li>\n<li>\u4e0e Mapper \u65b9\u6cd5\u5165\u53c2\u53d8\u91cf\u540d\u65e0\u5173&#xff08;\u5982int add(User u)&#xff0c;\u5165\u53c2\u540d u \u4e0d\u5f71\u54cd\u5339\u914d&#xff09;&#xff1b;<\/li>\n<li>\u7f16\u8bd1\u671f\u65e0\u8bed\u6cd5\u9519\u8bef&#xff0c;\u5c5e\u6027\u540d\u4e0d\u5339\u914d\u65f6\u8fd0\u884c\u65f6\u62a5\u9519&#xff08;\u63d0\u793a\u627e\u4e0d\u5230\u5bf9\u5e94\u7684getter\u65b9\u6cd5&#xff09;\u3002<\/li>\n<\/ul>\n<h4>2. \u4f20\u5355\u4e2a\u57fa\u672c\u7c7b\u578b \/ \u5b57\u7b26\u4e32<\/h4>\n<ul>\n<li>#{\u5360\u4f4d\u7b26\u540d} \u53ef\u4efb\u610f\u5199&#xff08;MyBatis \u5bf9\u5355\u4e2a\u57fa\u672c\u53c2\u6570\u65e0\u547d\u540d\u8981\u6c42&#xff09;&#xff0c;\u5efa\u8bae\u4e0e\u5f62\u53c2\u540d\u4e00\u81f4\u589e\u5f3a\u53ef\u8bfb\u6027\u3002<\/li>\n<\/ul>\n<h4>3. \u4f20 Map \u5bf9\u8c61<\/h4>\n<ul>\n<li>#{\u5360\u4f4d\u7b26\u540d} \u5fc5\u987b\u4e0e Map \u7684key \u503c\u4e25\u683c\u4e00\u81f4\u3002<\/li>\n<\/ul>\n<h4>4. \u591a\u53c2\u6570\u4f20\u53c2<\/h4>\n<ul>\n<li>\u65e0 &#064;Param \u65f6\u76f4\u63a5\u8fd0\u884c\u62a5\u9519&#xff08;\u63d0\u793aParameter &#039;xxx&#039; not found&#xff09;&#xff0c;\u591a\u53c2\u6570\u5fc5\u987b\u52a0 &#064;Param \u6ce8\u89e3\u3002<\/li>\n<\/ul>\n<h3>\u56db\u3001&#064;Param \u6ce8\u89e3\u6838\u5fc3\u4f7f\u7528<\/h3>\n<h4>1. \u6838\u5fc3\u4f5c\u7528<\/h4>\n<p>\u7ed9 Mapper \u65b9\u6cd5\u7684\u53c2\u6570\u6307\u5b9a\u552f\u4e00\u522b\u540d&#xff0c;\u8ba9 MyBatis \u7ed1\u5b9a#{\u5360\u4f4d\u7b26\u540d}&#xff0c;\u7a81\u7834\u539f\u751f\u5f62\u53c2\u540d\u9650\u5236&#xff0c;\u662f\u591a\u53c2\u6570\u4f20\u53c2\u7684\u6807\u914d\u3002<\/p>\n<h4>2. \u57fa\u7840\u4f7f\u7528\u573a\u666f<\/h4>\n<h5>&#xff08;1&#xff09;\u591a\u57fa\u672c\u7c7b\u578b\u53c2\u6570<\/h5>\n<p>\/\/ &#064;Param\u522b\u540d\u4e0e#{\u5360\u4f4d\u7b26\u540d}\u4e00\u81f4&#xff0c;\u4e0e\u539f\u5f62\u53c2\u540d\u65e0\u5173<br \/>\n&#064;Delete(&#034;DELETE FROM t_user WHERE id &#061; #{t_id}&#034;)<br \/>\nint deleteUserById(&#064;Param(&#034;t_id&#034;) Integer id);<\/p>\n<h5>&#xff08;2&#xff09;\u5b9e\u4f53\u7c7b &#043; \u57fa\u672c\u7c7b\u578b\u6df7\u5408\u4f20\u53c2<\/h5>\n<p>\/\/ \u5b9e\u4f53\u7c7b\u52a0&#064;Param\u540e&#xff0c;\u5360\u4f4d\u7b26\u9700\u5199\u300c\u522b\u540d.\u5b9e\u4f53\u5c5e\u6027\u540d\u300d<br \/>\n&#064;Insert(&#034;INSERT INTO t_user(username, create_time) VALUES (#{user.username}, #{createTime})&#034;)<br \/>\nint addUser(&#064;Param(&#034;user&#034;) User user, &#064;Param(&#034;createTime&#034;) LocalDateTime createTime);<\/p>\n<h4>3. \u5173\u952e\u7279\u6027<\/h4>\n<ul>\n<li>\u52a0 &#064;Param \u540e&#xff0c;#{\u5360\u4f4d\u7b26\u540d} \u4ec5\u4e0e &#064;Param \u7684 value \u503c\u4e00\u81f4&#xff0c;\u4e0e\u539f\u5f62\u53c2\u540d\u5b8c\u5168\u65e0\u5173&#xff1b;<\/li>\n<li>\u5355\u4e2a\u53c2\u6570\u4e5f\u53ef\u52a0 &#064;Param&#xff08;\u4e07\u80fd\u5199\u6cd5&#xff0c;\u65e0\u517c\u5bb9\u95ee\u9898&#xff09;&#xff0c;\u63a8\u8350\u56e2\u961f\u5f00\u53d1\u7edf\u4e00\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<h4>4. \u5b57\u8282\u7801\u5c42\u9762\u539f\u7406<\/h4>\n<ul>\n<li>&#064;Param\u4e0d\u4f1a\u4fee\u6539\u5b57\u8282\u7801\u4e2d\u7684\u539f\u751f\u5f62\u53c2\u540d&#xff0c;\u9ed8\u8ba4\u7f16\u8bd1&#xff08;\u672a\u5f00-parameters&#xff09;\u4e0b\u5f62\u53c2\u4f1a\u88ab\u7f16\u8bd1\u4e3aarg0\/arg1&#xff08;\u800c\u975e var1\/var2&#xff09;&#xff1b;<\/li>\n<li>&#064;Param \u7684\u522b\u540d\u4ee5\u8fd0\u884c\u65f6\u53ef\u89c1\u7684\u53c2\u6570\u6ce8\u89e3\u5143\u6570\u636e\u5b58\u50a8\u5728\u5b57\u8282\u7801\u4e2d&#xff0c;MyBatis \u8fd0\u884c\u65f6\u901a\u8fc7\u53cd\u5c04\u8bfb\u53d6\u8be5\u5143\u6570\u636e\u5b9e\u73b0\u53c2\u6570\u7ed1\u5b9a&#xff0c;\u7ed5\u5f00\u539f\u751f\u5f62\u53c2\u540d\u4e22\u5931\u95ee\u9898\u3002<\/li>\n<\/ul>\n<h3>\u4e94\u3001\u7f16\u8bd1\u53c2\u6570-parameters\u4e0e MyBatis \u7248\u672c\u5173\u8054<\/h3>\n<h4>1. \u6838\u5fc3\u5dee\u5f02&#xff08;\u662f\u5426\u9700\u8981 &#064;Param&#xff09;<\/h4>\n<ul>\n<li>MyBatis 3.4.0&#043;&#xff08;JDK8&#043;&#xff09;&#xff1a;\u5f00-parameters\u53ef\u4fdd\u7559\u539f\u751f\u5f62\u53c2\u540d&#xff0c;\u5355\u57fa\u672c\u53c2\u6570\u53ef\u7701\u7565 &#064;Param&#xff1b;\u591a\u53c2\u6570\u4ecd\u5fc5\u987b\u52a0&#xff1b;<\/li>\n<li>MyBatis 3.4.0 \u4e4b\u524d&#xff1a;\u65e0\u8bba\u662f\u5426\u5f00-parameters&#xff0c;\u6240\u6709\u53c2\u6570&#xff08;\u542b\u5355\u53c2\u6570&#xff09;\u5fc5\u987b\u52a0 &#064;Param&#xff0c;\u5426\u5219\u8fd0\u884c\u62a5\u9519\u3002<\/li>\n<\/ul>\n<h4>2. \u6846\u67b6\u65e0\u5173\u6027<\/h4>\n<p>\u662f\u5426\u9700\u8981\u52a0 &#064;Param\u4e0e Spring Boot \u65e0\u5173&#xff0c;\u4ec5\u7531 MyBatis \u7248\u672c\u548c-parameters\u7f16\u8bd1\u914d\u7f6e\u51b3\u5b9a&#xff1b;<\/p>\n<ul>\n<li>Spring Boot \u9ed8\u8ba4\u5f00\u542f-parameters&#xff0c;\u4e14\u6574\u5408\u9ad8\u7248\u672c MyBatis&#xff0c;\u652f\u6301\u5355\u53c2\u6570\u7701 &#064;Param&#xff1b;<\/li>\n<li>\u975e Spring Boot \u9879\u76ee\u9ed8\u8ba4\u672a\u5f00-parameters&#xff0c;\u539f\u751f\u5f62\u53c2\u540d\u4f1a\u4e22\u5931&#xff0c;\u5355\u53c2\u6570\u5efa\u8bae\u52a0 &#064;Param \u907f\u514d\u62a5\u9519\u3002<\/li>\n<\/ul>\n<h4>3. \u4f18\u5148\u7ea7<\/h4>\n<p>MyBatis \u8fd0\u884c\u65f6\u4f18\u5148\u8bfb\u53d6 &#064;Param \u6ce8\u89e3\u7684\u522b\u540d&#xff0c;\u5373\u4f7f\u5f00\u542f-parameters\u4fdd\u7559\u4e86\u539f\u751f\u5f62\u53c2\u540d&#xff0c;\u4e5f\u4f1a\u5ffd\u7565\u539f\u751f\u540d\u3002<\/p>\n<h3>\u516d\u3001\u5e38\u89c1\u8fd0\u884c\u65f6\u9519\u8bef &amp; \u907f\u5751\u6280\u5de7<\/h3>\n<h4>1. \u5178\u578b\u62a5\u9519\u7c7b\u578b<\/h4>\n<ul>\n<li>Parameter &#039;xxx&#039; not found&#xff1a;\u591a\u53c2\u6570\u65e0 &#064;Param\u3001&#064;Param \u522b\u540d\u4e0e\u5360\u4f4d\u7b26\u540d\u4e0d\u5339\u914d\u3001Map key \/ \u5b9e\u4f53\u5c5e\u6027\u540d\u4e0e\u5360\u4f4d\u7b26\u540d\u4e0d\u5339\u914d&#xff1b;<\/li>\n<li>\u627e\u4e0d\u5230\u5bf9\u5e94\u7684getter\u65b9\u6cd5&#xff1a;\u5b9e\u4f53\u5c5e\u6027\u540d\u4e0e\u5360\u4f4d\u7b26\u540d\u4e0d\u5339\u914d\u3001\u5927\u5c0f\u5199\u4e0d\u4e00\u81f4\u3002<\/li>\n<\/ul>\n<h4>2. \u907f\u5751\u6280\u5de7<\/h4>\n<li>\u5f00\u53d1\u671f\u4f7f\u7528 IDEA \u63d2\u4ef6&#xff08;\u5982Free MyBatis Plugin&#xff09;&#xff0c;\u5b9e\u65f6\u6821\u9a8c\u53c2\u6570\u6620\u5c04&#xff0c;\u7f16\u8f91\u5668\u6807\u7ea2\u9519\u8bef&#xff0c;\u65e0\u9700\u7b49\u5230\u8fd0\u884c\u65f6&#xff1b;<\/li>\n<li>\u5b9e\u4f53\u7c7b\u642d\u914d Lombok \u65f6&#xff0c;\u5fc5\u987b\u52a0&#064;NoArgsConstructor &#043; &#064;Data&#xff08;MyBatis \u9700\u8981\u65e0\u53c2\u6784\u9020\u521b\u5efa\u5bf9\u8c61&#xff0c;getter\/setter \u8d4b\u503c&#xff09;&#xff1b;<\/li>\n<li>\u5168\u7248\u672c \/ \u5168\u6846\u67b6\u4e07\u80fd\u517c\u5bb9\u5199\u6cd5&#xff1a;\u6240\u6709 Mapper \u65b9\u6cd5\u53c2\u6570\u90fd\u52a0 &#064;Param \u6ce8\u89e3&#xff0c;\u6c38\u65e0\u53c2\u6570\u5339\u914d\u95ee\u9898\u3002<\/li>\n<h3>7. XML \u6620\u5c04\u914d\u7f6e<\/h3>\n<h4>\u4e00\u3001\u6838\u5fc3\u6982\u5ff5<\/h4>\n<p>MyBatis \u652f\u6301\u4e24\u79cd SQL \u914d\u7f6e\u65b9\u5f0f&#xff1a;\u6ce8\u89e3\u914d\u7f6e\u548cXML \u914d\u7f6e\u6587\u4ef6\u3002XML \u6620\u5c04\u914d\u7f6e\u662f\u66f4\u5e38\u7528\u7684\u65b9\u5f0f&#xff0c;\u5c24\u5176\u9002\u5408\u590d\u6742 SQL \u573a\u666f\u3002<\/p>\n<h4>\u4e8c\u3001\u9ed8\u8ba4\u89c4\u5219&#xff08;\u5fc5\u987b\u9075\u5b88&#xff09;<\/h4>\n<li>\n<p>\u540c\u5305\u540c\u540d<\/p>\n<p>XML \u6620\u5c04\u6587\u4ef6\u7684\u540d\u79f0\u5fc5\u987b\u4e0e Mapper \u63a5\u53e3\u540d\u79f0\u5b8c\u5168\u4e00\u81f4&#xff0c;\u5e76\u4e14\u8981\u653e\u5728\u540c\u4e00\u4e2a\u5305\u4e0b\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>UserMapper.java<\/p>\n<p>\u548c<\/p>\n<p>UserMapper.xml<\/p>\n<p>\u90fd\u5728<\/p>\n<p>com.mybatisdemo.mapper<\/p>\n<p>\u5305\u4e0b\u3002<\/p>\n<\/li>\n<li>\n<p>namespace \u4e00\u81f4<\/p>\n<p>XML \u6620\u5c04\u6587\u4ef6\u4e2d\u7684<\/p>\n<p>namespace<\/p>\n<p>\u5c5e\u6027\u503c&#xff0c;\u5fc5\u987b\u662f\u5bf9\u5e94 Mapper \u63a5\u53e3\u7684\u5168\u9650\u5b9a\u540d\u3002<\/p>\n<p>&lt;mapper namespace&#061;&#034;com.mybatisdemo.mapper.UserMapper&#034;&gt;<\/p>\n<\/li>\n<li>\n<p>ID \u4e0e\u8fd4\u56de\u503c\u4e00\u81f4<\/p>\n<p>XML \u4e2d SQL \u8bed\u53e5\u7684<\/p>\n<p>id<\/p>\n<p>\u5fc5\u987b\u4e0e Mapper \u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5\u540d\u5b8c\u5168\u4e00\u81f4\u3002<\/p>\n<p>\u8fd4\u56de\u7c7b\u578b&#xff08;<\/p>\n<p>resultType<\/p>\n<p>&#xff09;\u4e5f\u5fc5\u987b\u4e0e\u63a5\u53e3\u65b9\u6cd5\u7684\u8fd4\u56de\u7c7b\u578b\u5339\u914d\u3002<\/p>\n<p>\/\/ Mapper\u63a5\u53e3\u65b9\u6cd5<br \/>\nList&lt;User&gt; findAll();<\/p>\n<p>&lt;!&#8211; XML\u4e2d\u7684\u5bf9\u5e94SQL &#8211;&gt;<br \/>\n&lt;select id&#061;&#034;findAll&#034; resultType&#061;&#034;com.mybatisdemo.pojo.User&#034;&gt;<br \/>\n    select id, username, password, name, age from user<br \/>\n&lt;\/select&gt;<\/p>\n<\/li>\n<h4>\u4e09\u3001\u5173\u952e\u914d\u7f6e\u8bf4\u660e<\/h4>\n<ul>\n<li>\u8fd4\u56de\u96c6\u5408\u7684\u7279\u6b8a\u5904\u7406&#xff1a;\u5f53\u63a5\u53e3\u65b9\u6cd5\u8fd4\u56de List&lt;User&gt; \u65f6&#xff0c;XML \u4e2d\u7684 resultType \u53ea\u9700\u5199\u5355\u4e2a\u5b9e\u4f53\u7c7b\u7684\u5168\u9650\u5b9a\u540d&#xff08;\u5982 com.mybatisdemo.pojo.User&#xff09;&#xff0c;MyBatis \u4f1a\u81ea\u52a8\u5c06\u7ed3\u679c\u5c01\u88c5\u4e3a List \u96c6\u5408\u3002<\/li>\n<li>\u522b\u540d\u4f18\u5316&#xff1a;\u5982\u679c\u5728 MyBatis \u5168\u5c40\u914d\u7f6e\u4e2d\u7ed9\u5b9e\u4f53\u7c7b\u914d\u7f6e\u4e86\u522b\u540d&#xff0c;resultType \u53ef\u4ee5\u76f4\u63a5\u5199\u522b\u540d&#xff08;\u5982 User&#xff09;&#xff0c;\u7b80\u5316\u914d\u7f6e\u3002<\/li>\n<\/ul>\n<h4>\u56db\u3001\u9879\u76ee\u7ed3\u6784\u793a\u4f8b<\/h4>\n<p>mybatis-demo<br \/>\n\u2514\u2500\u2500 src<br \/>\n    \u2514\u2500\u2500 main<br \/>\n        \u251c\u2500\u2500 java<br \/>\n        \u2502   \u2514\u2500\u2500 com.mybatisdemo<br \/>\n        \u2502       \u251c\u2500\u2500 mapper<br \/>\n        \u2502       \u2502   \u2514\u2500\u2500 UserMapper.java<br \/>\n        \u2502       \u251c\u2500\u2500 pojo<br \/>\n        \u2502       \u2502   \u2514\u2500\u2500 User.java<br \/>\n        \u2502       \u2514\u2500\u2500 MybatisDemoApplication.java<br \/>\n        \u2514\u2500\u2500 resources<br \/>\n            \u251c\u2500\u2500 com.mybatisdemo.mapper<br \/>\n            \u2502   \u2514\u2500\u2500 UserMapper.xml<br \/>\n            \u2514\u2500\u2500 application.properties<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MyBatis<br \/>\n\u4e00\u3001\u81ea\u589e ID \u63d2\u5165\u89c4\u5219<br \/>\n\u6570\u636e\u5e93\u5b57\u6bb5\u8bbe\u4e3a\u81ea\u589e&#xff08;\u5982 MySQL AUTO_INCREMENT&#xff09;&#xff0c;INSERT \u8bed\u53e5\u7701\u7565\u81ea\u589e\u5b57\u6bb5&#xff0c;\u6570\u636e\u5e93\u81ea\u52a8\u751f\u6210 ID&#xff1b;\u5b9e\u4f53\u7c7b\u4e2d\u81ea\u589e\u5b57\u6bb5\u65e0\u9700\u8d4b\u503c&#xff08;\u9ed8\u8ba4 null \u5373\u53ef&#xff09;&#xff0c;MyBatis \u53ef\u901a\u8fc7Options(useGeneratedKeys  true, keyProperty  \\&#8221;id\\&#8221;)\u5c06\u751f\u6210\u7684 ID \u56de\u663e\u5230\u5b9e\u4f53&amp;#x<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1769,371,305],"topic":[],"class_list":["post-69103","post","type-post","status-publish","format-standard","hentry","category-server","tag-mybatis","tag-371","tag-305"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>day-8 MyBatis - \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\/69103.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"day-8 MyBatis - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"MyBatis \u4e00\u3001\u81ea\u589e ID \u63d2\u5165\u89c4\u5219 \u6570\u636e\u5e93\u5b57\u6bb5\u8bbe\u4e3a\u81ea\u589e&#xff08;\u5982 MySQL AUTO_INCREMENT&#xff09;&#xff0c;INSERT \u8bed\u53e5\u7701\u7565\u81ea\u589e\u5b57\u6bb5&#xff0c;\u6570\u636e\u5e93\u81ea\u52a8\u751f\u6210 ID&#xff1b;\u5b9e\u4f53\u7c7b\u4e2d\u81ea\u589e\u5b57\u6bb5\u65e0\u9700\u8d4b\u503c&#xff08;\u9ed8\u8ba4 null \u5373\u53ef&#xff09;&#xff0c;MyBatis \u53ef\u901a\u8fc7Options(useGeneratedKeys true, keyProperty &quot;id&quot;)\u5c06\u751f\u6210\u7684 ID \u56de\u663e\u5230\u5b9e\u4f53&amp;#x\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/69103.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-30T21:05:06+00:00\" \/>\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=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/69103.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/69103.html\",\"name\":\"day-8 MyBatis - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-30T21:05:06+00:00\",\"dateModified\":\"2026-01-30T21:05:06+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/69103.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/69103.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/69103.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"day-8 MyBatis\"}]},{\"@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":"day-8 MyBatis - \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\/69103.html","og_locale":"zh_CN","og_type":"article","og_title":"day-8 MyBatis - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"MyBatis \u4e00\u3001\u81ea\u589e ID \u63d2\u5165\u89c4\u5219 \u6570\u636e\u5e93\u5b57\u6bb5\u8bbe\u4e3a\u81ea\u589e&#xff08;\u5982 MySQL AUTO_INCREMENT&#xff09;&#xff0c;INSERT \u8bed\u53e5\u7701\u7565\u81ea\u589e\u5b57\u6bb5&#xff0c;\u6570\u636e\u5e93\u81ea\u52a8\u751f\u6210 ID&#xff1b;\u5b9e\u4f53\u7c7b\u4e2d\u81ea\u589e\u5b57\u6bb5\u65e0\u9700\u8d4b\u503c&#xff08;\u9ed8\u8ba4 null \u5373\u53ef&#xff09;&#xff0c;MyBatis \u53ef\u901a\u8fc7Options(useGeneratedKeys true, keyProperty \"id\")\u5c06\u751f\u6210\u7684 ID \u56de\u663e\u5230\u5b9e\u4f53&amp;#x","og_url":"https:\/\/www.wsisp.com\/helps\/69103.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-30T21:05:06+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/69103.html","url":"https:\/\/www.wsisp.com\/helps\/69103.html","name":"day-8 MyBatis - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-30T21:05:06+00:00","dateModified":"2026-01-30T21:05:06+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/69103.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/69103.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/69103.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"day-8 MyBatis"}]},{"@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\/69103","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=69103"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/69103\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=69103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=69103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=69103"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=69103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}