{"id":52930,"date":"2025-08-11T21:39:12","date_gmt":"2025-08-11T13:39:12","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/52930.html"},"modified":"2025-08-11T21:39:12","modified_gmt":"2025-08-11T13:39:12","slug":"mybatis%e7%9b%b8%e5%85%b3%e7%9f%a5%e8%af%86%e7%82%b9%e6%80%bb%e7%bb%93","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/52930.html","title":{"rendered":"MyBatis\u76f8\u5173\u77e5\u8bc6\u70b9\u603b\u7ed3"},"content":{"rendered":"<h2>\u4e00\u3001\u4ec0\u4e48\u662fMybatis<\/h2>\n<p>MyBatis \u662f\u4e00\u6b3e\u4f18\u79c0\u7684\u6301\u4e45\u5c42\u6846\u67b6&#xff0c;\u5b83\u652f\u6301\u81ea\u5b9a\u4e49 SQL\u3001\u5b58\u50a8\u8fc7\u7a0b\u4ee5\u53ca\u9ad8\u7ea7\u6620\u5c04\u3002MyBatis \u514d\u9664\u4e86\u51e0\u4e4e\u6240\u6709\u7684 JDBC \u4ee3\u7801\u4ee5\u53ca\u8bbe\u7f6e\u53c2\u6570\u548c\u83b7\u53d6\u7ed3\u679c\u96c6\u7684\u5de5\u4f5c\u3002<span style=\"color:#333333\">Mybatis\u662f\u4e00\u4e2a\u534a<\/span><span style=\"color:#333333\">ORM<\/span><span style=\"color:#333333\">&#xff08;\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04&#xff09;\u6846\u67b6&#xff0c;\u5b83\u5185\u90e8\u5c01\u88c5\u4e86<\/span><span style=\"color:#333333\">JDBC<\/span><span style=\"color:#333333\">&#xff0c;\u52a0\u8f7d\u9a71\u52a8\u3001\u521b\u5efa\u8fde\u63a5\u3001\u521b\u5efa statement\u7b49\u7e41\u6742\u7684\u8fc7\u7a0b&#xff0c;\u5f00\u53d1\u8005\u5f00\u53d1\u65f6\u53ea\u9700\u8981\u5173\u6ce8\u5982\u4f55\u7f16\u5199<\/span><span style=\"color:#333333\">SQL<\/span><span style=\"color:#333333\">\u8bed\u53e5&#xff0c;\u53ef\u4ee5\u4e25\u683c\u63a7\u5236<\/span><span style=\"color:#333333\">sql<\/span><span style=\"color:#333333\">\u6267\u884c\u6027\u80fd&#xff0c;\u7075\u6d3b\u5ea6\u9ad8\u3002 <\/span><\/p>\n<p><span style=\"color:#333333\">\u4f5c\u4e3a\u4e00\u4e2a\u534a<\/span><span style=\"color:#333333\">ORM<\/span><span style=\"color:#333333\">\u6846\u67b6&#xff0c;<\/span><span style=\"color:#333333\">MyBatis <\/span><span style=\"color:#333333\">\u53ef\u4ee5\u4f7f\u7528<\/span><span style=\"color:#333333\"> XML <\/span><span style=\"color:#333333\">\u6216\u6ce8\u89e3\u6765\u914d\u7f6e\u548c\u6620\u5c04\u539f\u751f\u4fe1\u606f&#xff0c;\u5c06<\/span><span style=\"color:#333333\"> POJO<\/span><span style=\"color:#333333\">\u6620\u5c04\u6210\u6570<\/span><span style=\"color:#333333\">\u636e\u5e93\u4e2d\u7684\u8bb0\u5f55&#xff0c;\u907f\u514d\u4e86\u51e0\u4e4e\u6240\u6709\u7684<\/span><span style=\"color:#333333\"> JDBC <\/span><span style=\"color:#333333\">\u4ee3\u7801\u548c\u624b\u52a8\u8bbe\u7f6e\u53c2\u6570\u4ee5\u53ca\u83b7\u53d6\u7ed3\u679c\u96c6\u3002 <\/span><\/p>\n<p><span style=\"color:#333333\">\u901a\u8fc7<\/span><span style=\"color:#333333\">xml <\/span><span style=\"color:#333333\">\u6587\u4ef6\u6216\u6ce8\u89e3\u7684\u65b9\u5f0f\u5c06\u8981\u6267\u884c\u7684\u5404\u79cd<\/span><span style=\"color:#333333\"> statement <\/span><span style=\"color:#333333\">\u914d\u7f6e\u8d77\u6765&#xff0c;\u5e76\u901a\u8fc7<\/span><span style=\"color:#333333\">java<\/span><span style=\"color:#333333\">\u5bf9\u8c61\u548c<\/span><span style=\"color:#333333\"> statement<\/span><span style=\"color:#333333\">\u4e2d <\/span><\/p>\n<p><span style=\"color:#333333\">sql<\/span><span style=\"color:#333333\">\u7684\u52a8\u6001\u53c2\u6570\u8fdb\u884c\u6620\u5c04\u751f\u6210\u6700\u7ec8\u6267\u884c\u7684<\/span><span style=\"color:#333333\">sql<\/span><span style=\"color:#333333\">\u8bed\u53e5&#xff0c;\u6700\u540e\u7531<\/span><span style=\"color:#333333\">mybatis<\/span><span style=\"color:#333333\">\u6846\u67b6\u6267\u884c<\/span><span style=\"color:#333333\">sql<\/span><span style=\"color:#333333\">\u5e76\u5c06\u7ed3\u679c\u6620\u5c04\u4e3a<\/span><span style=\"color:#333333\">java <\/span><\/p>\n<p><span style=\"color:#333333\">\u5bf9\u8c61\u5e76\u8fd4\u56de\u3002&#xff08;\u4ece\u6267\u884c<\/span><span style=\"color:#333333\">sql<\/span><span style=\"color:#333333\">\u5230\u8fd4\u56de<\/span><span style=\"color:#333333\">result<\/span><span style=\"color:#333333\">\u7684\u8fc7\u7a0b&#xff09;\u3002 <\/span><\/p>\n<p><span style=\"color:#333333\">\u7531\u4e8e<\/span><span style=\"color:#333333\">MyBatis<\/span><span style=\"color:#333333\">\u4e13\u6ce8\u4e8e<\/span><span style=\"color:#333333\">SQL<\/span><span style=\"color:#333333\">\u672c\u8eab&#xff0c;\u7075\u6d3b\u5ea6\u9ad8&#xff0c;\u6240\u4ee5\u6bd4\u8f83\u9002\u5408\u5bf9\u6027\u80fd\u7684\u8981\u6c42\u5f88\u9ad8&#xff0c;\u6216\u8005\u9700\u6c42\u53d8\u5316\u8f83\u591a\u7684 <\/span><\/p>\n<p><span style=\"color:#333333\">\u9879\u76ee&#xff0c;\u5982\u4e92\u8054\u7f51\u9879\u76ee\u3002 <\/span><\/p>\n<h3><span style=\"color:#333333\">1.1\u4ec0\u4e48\u662fORM<\/span><\/h3>\n<p><span style=\"color:#777777\">ORM(Object-relational mapping)<\/span><span style=\"color:#777777\">&#xff0c;\u5373<\/span><span style=\"color:#777777\">\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04<\/span><span style=\"color:#777777\">&#xff0c;<\/span><span style=\"color:#777777\">\u662f\u4e00\u79cd\u4e3a\u4e86\u89e3\u51b3\u9762\u5411\u5bf9\u8c61\u4e0e\u5173\u7cfb\u6570\u636e\u5e93\u5b58 <\/span><\/p>\n<p><span style=\"color:#777777\">\u5728\u7684\u4e92\u4e0d\u5339\u914d\u7684\u73b0\u8c61\u7684\u6280\u672f\u3002<\/span><span style=\"color:#777777\">\u7b80\u5355\u7684\u8bf4&#xff0c;<\/span><span style=\"color:#777777\">ORM<\/span><span style=\"color:#777777\">\u662f\u901a\u8fc7\u4f7f\u7528\u63cf\u8ff0\u5bf9\u8c61\u548c\u6570\u636e\u5e93\u4e4b\u95f4\u6620\u5c04\u7684\u5143\u6570\u636e&#xff0c; <\/span><\/p>\n<p><span style=\"color:#777777\">\u5c06\u7a0b\u5e8f\u4e2d\u7684\u5bf9\u8c61\u81ea\u52a8\u6301\u4e45\u5316\u5230\u5173\u7cfb\u6570\u636e\u5e93\u4e2d\u3002<\/span><\/p>\n<p>1\u3001O-&gt;R add\/insert\/save<\/p>\n<p>studentDao.insert(student)<\/p>\n<p>\u628a\u4e00\u4e2ajava\u5bf9\u8c61\u4fdd\u5b58\u5230\u6570\u636e\u5e93\u4e2d\u7684\u4e00\u884c\u8bb0\u5f55<\/p>\n<p>2\u3001R-&gt;O selectById\/findById\/listById<\/p>\n<p>Student student &#061; sudentDao.findById(id)<\/p>\n<p>\u628a\u6570\u636e\u5e93\u91cc\u9762\u7684\u4e00\u884c\u8bb0\u5f55\u5c01\u88c5\u6210\u4e00\u4e2ajava\u5bf9\u8c61<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"430\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250811133910-6899f27e92f9f.png\" width=\"949\" \/><\/p>\n<h3><span style=\"color:#333333\">1.2\u00a0Mybaits<\/span><span style=\"color:#333333\">\u7684\u4f18\u7f3a\u70b9 <\/span><\/h3>\n<p><span style=\"color:#333333\">\u4f18\u70b9 <\/span><\/p>\n<p><span style=\"color:#333333\">\u57fa\u4e8e<\/span><span style=\"color:#333333\">SQL<\/span><span style=\"color:#333333\">\u8bed\u53e5\u7f16\u7a0b&#xff0c;\u76f8\u5f53\u7075\u6d3b&#xff0c;\u4e0d\u4f1a\u5bf9\u5e94\u7528\u7a0b\u5e8f\u6216\u8005\u6570\u636e\u5e93\u7684\u73b0\u6709\u8bbe\u8ba1\u9020\u6210\u4efb\u4f55\u5f71\u54cd&#xff0c;<\/span><span style=\"color:#333333\">SQL<\/span><span style=\"color:#333333\">\u5199\u5728 <\/span><\/p>\n<p><span style=\"color:#333333\">XML<\/span><span style=\"color:#333333\">\u91cc&#xff0c;\u89e3\u9664<\/span><span style=\"color:#333333\">sql<\/span><span style=\"color:#333333\">\u4e0e\u7a0b\u5e8f\u4ee3\u7801\u7684\u8026\u5408&#xff0c;\u4fbf\u4e8e\u7edf\u4e00\u7ba1\u7406<\/span><span style=\"color:#333333\">&#xff1b;\u63d0\u4f9b<\/span><span style=\"color:#333333\">XML<\/span><span style=\"color:#333333\">\u6807\u7b7e&#xff0c;\u652f\u6301\u7f16\u5199\u52a8\u6001<\/span><span style=\"color:#333333\">SQL<\/span><span style=\"color:#333333\">\u8bed\u53e5&#xff0c;\u5e76 <\/span><\/p>\n<p><span style=\"color:#333333\">\u53ef\u91cd\u7528\u3002 <\/span><\/p>\n<p><span style=\"color:#333333\">\u4e0e<\/span><span style=\"color:#333333\">JDBC<\/span><span style=\"color:#333333\">\u76f8\u6bd4&#xff0c;\u51cf\u5c11\u4e86<\/span><span style=\"color:#333333\">50%<\/span><span style=\"color:#333333\">\u4ee5\u4e0a\u7684\u4ee3\u7801\u91cf&#xff0c;\u6d88\u9664\u4e86<\/span><span style=\"color:#333333\">JDBC<\/span><span style=\"color:#333333\">\u5927\u91cf\u5197\u4f59\u7684\u4ee3\u7801&#xff0c;\u4e0d\u9700\u8981\u624b\u52a8\u5f00\u5173\u8fde\u63a5&#xff1b; <\/span><\/p>\n<p><span style=\"color:#333333\">\u5f88\u597d\u7684\u4e0e\u5404\u79cd\u6570\u636e\u5e93\u517c\u5bb9&#xff08;\u56e0\u4e3a<\/span><span style=\"color:#333333\">MyBatis<\/span><span style=\"color:#333333\">\u4f7f\u7528<\/span><span style=\"color:#333333\">JDBC<\/span><span style=\"color:#333333\">\u6765\u8fde\u63a5\u6570\u636e\u5e93&#xff0c;\u6240\u4ee5\u53ea\u8981<\/span><span style=\"color:#333333\">JDBC<\/span><span style=\"color:#333333\">\u652f\u6301\u7684\u6570\u636e\u5e93 <\/span><\/p>\n<p><span style=\"color:#333333\">MyBatis<\/span><span style=\"color:#333333\">\u90fd\u652f\u6301&#xff09;\u3002 <\/span><\/p>\n<p><span style=\"color:#333333\">\u80fd\u591f\u4e0e<\/span><span style=\"color:#333333\">Spring<\/span><span style=\"color:#333333\">\u5f88\u597d\u7684\u96c6\u6210&#xff1b; \u63d0\u4f9b\u6620\u5c04\u6807\u7b7e&#xff0c;\u652f\u6301\u5bf9\u8c61\u4e0e\u6570\u636e\u5e93\u7684<\/span><span style=\"color:#333333\">ORM<\/span><span style=\"color:#333333\">\u5b57\u6bb5\u5173\u7cfb\u6620\u5c04&#xff1b; <\/span><\/p>\n<p><span style=\"color:#333333\">\u63d0\u4f9b\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04\u6807\u7b7e&#xff0c;\u652f\u6301\u5bf9\u8c61\u5173\u7cfb\u7ec4\u4ef6\u7ef4\u62a4\u3002 <\/span><\/p>\n<p><span style=\"color:#333333\">\u7f3a\u70b9 <\/span><\/p>\n<p><span style=\"color:#333333\">SQL<\/span><span style=\"color:#333333\">\u8bed\u53e5\u7684\u7f16\u5199\u5de5\u4f5c\u91cf\u8f83\u5927&#xff0c;\u5c24\u5176\u5f53\u5b57\u6bb5\u591a\u3001\u5173\u8054\u8868\u591a\u65f6&#xff0c;\u5bf9\u5f00\u53d1\u4eba\u5458\u7f16\u5199<\/span><span style=\"color:#333333\">SQL<\/span><span style=\"color:#333333\">\u8bed\u53e5\u7684\u529f\u5e95\u6709\u4e00\u5b9a <\/span><\/p>\n<p><span style=\"color:#333333\">\u8981\u6c42\u3002 <\/span><\/p>\n<p><span style=\"color:#333333\">SQL<\/span><span style=\"color:#333333\">\u8bed\u53e5\u4f9d\u8d56\u4e8e\u6570\u636e\u5e93&#xff0c;\u5bfc\u81f4\u6570\u636e\u5e93\u79fb\u690d\u6027\u5dee&#xff0c;\u4e0d\u80fd\u968f\u610f\u66f4\u6362\u6570\u636e\u5e93\u3002<\/span><\/p>\n<h2>\u4e8c\u3001Mybatis\u58f0\u660e\u63a5\u53e3<\/h2>\n<p>MyBatis \u901a\u8fc7\u63a5\u53e3\u4e0e SQL \u8bed\u53e5\u8fdb\u884c\u6620\u5c04&#xff0c;\u65e0\u9700\u5b9e\u73b0\u7c7b\u5373\u53ef\u76f4\u63a5\u8c03\u7528\u3002\u63a5\u53e3\u901a\u5e38\u4e0e Mapper \u7ed1\u5b9a&#xff0c;\u5b9a\u4e49\u6570\u636e\u64cd\u4f5c\u65b9\u6cd5\u3002<\/p>\n<h3>2.1CourseMapper\u63a5\u53e3<\/h3>\n<p>&#064;Mapper \/\/ \u6807\u8bc6\u8be5\u63a5\u53e3\u4e3aMyBatis\u6620\u5c04\u5668&#xff0c;MyBatis\u4f1a\u52a8\u6001\u751f\u6210\u5176\u5b9e\u73b0\u7c7b<br \/>\npublic interface CourseMapper {<br \/>\n    \/\/ \u6839\u636e\u8bfe\u7a0bID\u67e5\u8be2\u8bfe\u7a0b\u4fe1\u606f<br \/>\n    Course getByID(&#064;Param(&#034;id&#034;) Integer id);  <\/p>\n<p>    \/\/ \u6839\u636e\u6761\u4ef6\u52a8\u6001\u67e5\u8be2\u8bfe\u7a0b\u5217\u8868<br \/>\n    List&lt;Course&gt; list(&#064;Param(&#034;course&#034;) Course course);  <\/p>\n<p>    \/\/ \u65b0\u589e\u8bfe\u7a0b\u4fe1\u606f<br \/>\n    int add(&#064;Param(&#034;course&#034;) Course course);  <\/p>\n<p>    \/\/ \u4fee\u6539\u8bfe\u7a0b\u4fe1\u606f<br \/>\n    int edit(&#064;Param(&#034;course&#034;) Course course);  <\/p>\n<p>    \/\/ \u5220\u9664\u8bfe\u7a0b\u4fe1\u606f<br \/>\n    int delete(&#064;Param(&#034;course&#034;) Course course);<br \/>\n}  <\/p>\n<h3>2.2TeacherMapper \u63a5\u53e3<\/h3>\n<p>&#064;Mapper \/\/ MyBatis\u6620\u5c04\u5668\u63a5\u53e3<br \/>\npublic interface TeacherMapper {<br \/>\n    \/\/ \u65b0\u589e\u5355\u4e2a\u6559\u5e08\u4fe1\u606f<br \/>\n    int add(&#064;Param(&#034;teacher&#034;) Teacher teacher);  <\/p>\n<p>    \/\/ \u6279\u91cf\u65b0\u589e\u6559\u5e08\u4fe1\u606f<br \/>\n    int addTeachers(&#064;Param(&#034;teachers&#034;) List&lt;Teacher&gt; teachers);  <\/p>\n<p>    \/\/ \u6839\u636eID\u5220\u9664\u6559\u5e08\u4fe1\u606f<br \/>\n    int delete(&#064;Param(&#034;id&#034;) Integer id);  <\/p>\n<p>    \/\/ \u4fee\u6539\u6559\u5e08\u4fe1\u606f<br \/>\n    int edit(&#064;Param(&#034;teacher&#034;) Teacher teacher);  <\/p>\n<p>    \/\/ \u67e5\u8be2\u6240\u6709\u6559\u5e08\u5217\u8868<br \/>\n    List&lt;Teacher&gt; list();  <\/p>\n<p>    \/\/ \u6839\u636eID\u67e5\u8be2\u6559\u5e08\u4fe1\u606f<br \/>\n    Teacher getByID(&#064;Param(&#034;id&#034;) Integer id);  <\/p>\n<p>    \/\/ \u52a8\u6001\u6761\u4ef6\u67e5\u8be2\u6559\u5e08\u5217\u8868<br \/>\n    List&lt;Teacher&gt; listSearch(&#064;Param(&#034;teacher&#034;) Teacher teacher);<br \/>\n}  <\/p>\n<h2>\u4e09\u3001\u7ed1\u5b9asql\u65b9\u5f0f<\/h2>\n<h2 id=\"9VMb-1754917879093\">\u4ee5\u53ca\u4e24\u79cd\u65b9\u5f0f\u7684\u589e\u5220\u6539\u67e5<\/h2>\n<h3 id=\"tC0R-1754917879095\">3.1. \u6ce8\u89e3\u65b9\u5f0f\u5b9e\u73b0<\/h3>\n<p>\u76f4\u63a5\u5728\u63a5\u53e3\u65b9\u6cd5\u4e0a\u4f7f\u7528\u6ce8\u89e3\u7f16\u5199 SQL(StudentMapper)&#xff1a;<\/p>\n<p>&#064;Repository \/\/ \u6807\u8bc6\u4e3aSpring\u6570\u636e\u8bbf\u95ee\u5c42\u7ec4\u4ef6<br \/>\n&#064;Mapper \/\/ MyBatis\u6620\u5c04\u5668\u63a5\u53e3<br \/>\npublic interface StudentMapper {<br \/>\n    \/\/ \u6839\u636e\u5b66\u751fID\u67e5\u8be2\u5b66\u751f\u4fe1\u606f&#xff08;\u4f7f\u7528\u6ce8\u89e3SQL&#xff09;<br \/>\n    &#064;Select(&#034;SELECT * FROM student WHERE student_id &#061; #{stuid}&#034;)<br \/>\n    Student getStudentByid(&#064;Param(&#034;stuid&#034;) Integer id);  <\/p>\n<p>    \/\/ \u65b0\u589e\u5b66\u751f\u4fe1\u606f&#xff08;\u4f7f\u7528\u6ce8\u89e3SQL&#xff09;<br \/>\n    &#064;Insert(&#034;INSERT INTO student(student_name, birthday, gender, age) &#034; &#043;<br \/>\n            &#034;VALUES (#{student.student_name}, #{student.birthday}, #{student.gender}, #{student.age})&#034;)<br \/>\n    int addStudent(&#064;Param(&#034;student&#034;) Student student);  <\/p>\n<p>    \/\/ \u6839\u636e\u5b66\u751fID\u5220\u9664\u5b66\u751f\u4fe1\u606f&#xff08;\u4f7f\u7528\u6ce8\u89e3SQL&#xff09;<br \/>\n    &#064;Delete(&#034;DELETE FROM student WHERE student_id &#061; #{stuid}&#034;)<br \/>\n    int deleteStudent(&#064;Param(&#034;stuid&#034;) Integer id);  <\/p>\n<p>    \/\/ \u4fee\u6539\u5b66\u751f\u4fe1\u606f&#xff08;\u4f7f\u7528\u6ce8\u89e3SQL&#xff09;<br \/>\n    &#064;Update(&#034;UPDATE student SET student_name &#061; #{student.student_name}, &#034; &#043;<br \/>\n            &#034;gender &#061; #{student.gender}, age &#061; #{student.age} WHERE student_id &#061; #{student.student_id}&#034;)<br \/>\n    int editStudent(&#064;Param(&#034;student&#034;) Student student);  <\/p>\n<p>    \/\/ \u52a8\u6001\u6761\u4ef6\u67e5\u8be2\u5b66\u751f\u5217\u8868&#xff08;XML\u914d\u7f6eSQL&#xff09;<br \/>\n    List&lt;Student&gt; list1(&#064;Param(&#034;student&#034;) Student student);<br \/>\n}  <\/p>\n<h3 id=\"Kcvx-1754918187595\">3.2\u00a0XML \u6587\u4ef6\u65b9\u5f0f\u5b9e\u73b0<\/h3>\n<p>\u521b\u5efa\u5bf9\u5e94\u7684 Mapper XML \u6587\u4ef6&#xff08;teacherMapper.xml&#xff09;&#xff1a;<\/p>\n<p>&lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;UTF-8&#034;?&gt;<br \/>\n&lt;!DOCTYPE mapper PUBLIC &#034;-\/\/mybatis.org\/\/DTD Mapper 3.0\/\/EN&#034;<br \/>\n&#034;http:\/\/mybatis.org\/dtd\/mybatis-3-mapper.dtd&#034;&gt;<br \/>\n&lt;!&#8211; \u547d\u540d\u7a7a\u95f4\u9700\u4e0e\u63a5\u53e3\u5168\u8def\u5f84\u4e00\u81f4 &#8211;&gt;<br \/>\n&lt;mapper namespace&#061;&#034;com.example.mapper.UserMapper&#034;&gt;<\/p>\n<p>    &lt;!&#8211; \u67e5\u8be2 &#8211;&gt;<br \/>\n    &lt;select id&#061;&#034;getUserById&#034; parameterType&#061;&#034;java.lang.Integer&#034; resultMap&#061;&#034;BaseResultMap&#034;&gt;<br \/>\n        SELECT id, name, age, email FROM user WHERE id &#061; #{id}<br \/>\n    &lt;\/select&gt;<\/p>\n<p>    &lt;!&#8211; \u65b0\u589e &#8211;&gt;<br \/>\n    &lt;insert id&#061;&#034;insertUser&#034; parameterType&#061;&#034;com.example.entity.User&#034;<br \/>\n            useGeneratedKeys&#061;&#034;true&#034; keyProperty&#061;&#034;id&#034;&gt;<br \/>\n        INSERT INTO user(name, age, email) VALUES(#{name}, #{age}, #{email})<br \/>\n    &lt;\/insert&gt;<br \/>\n         useGeneratedKeys&#061;&#034;true&#034;&#xff1a;\u544a\u8bc9 MyBatis&#xff0c;\u5f53\u524d\u63d2\u5165\u64cd\u4f5c\u7684\u4e3b\u952e\u662f\u7531\u6570\u636e\u5e93\u81ea\u52a8\u751f\u6210\u7684<br \/>\n         keyProperty&#061;&#034;id&#034;&#xff1a;\u6307\u5b9a\u5c06\u6570\u636e\u5e93\u751f\u6210\u7684\u4e3b\u952e\u503c&#xff0c;\u8d4b\u503c\u7ed9\u4f20\u5165\u53c2\u6570\u5bf9\u8c61\u7684id\u5c5e\u6027\u3002<\/p>\n<p>    &lt;!&#8211; \u66f4\u65b0 &#8211;&gt;<br \/>\n    &lt;update id&#061;&#034;updateUser&#034; parameterType&#061;&#034;com.example.entity.User&#034;&gt;<br \/>\n        UPDATE user SET name &#061; #{name}, age &#061; #{age}, email &#061; #{email} WHERE id &#061; #{id}<br \/>\n    &lt;\/update&gt;<\/p>\n<p>    &lt;!&#8211; \u5220\u9664 &#8211;&gt;<br \/>\n    &lt;delete id&#061;&#034;deleteUser&#034; parameterType&#061;&#034;java.lang.Integer&#034;&gt;<br \/>\n        DELETE FROM user WHERE id &#061; #{id}<br \/>\n    &lt;\/delete&gt;<br \/>\n&lt;\/mapper&gt;<\/p>\n<h2 id=\"WRZE-1754918401172\" style=\"text-align:justify\">\u56db\u3001\u52a8\u6001sql\u8bed\u53e5\u7684\u6807\u7b7e<\/h2>\n<p><span style=\"color:#000000\"><span style=\"background-color:#f9fafb\">\u52a8\u6001 SQL \u7528\u4e8e\u6839\u636e\u6761\u4ef6\u52a8\u6001\u751f\u6210 SQL \u7247\u6bb5&#xff0c;\u5e38\u7528\u6807\u7b7e&#xff1a;<\/span><\/span><\/p>\n<p style=\"text-align:left\">\n<p>\u52a8\u6001 SQL \u662f MyBatis \u63d0\u4f9b\u7684\u4e00\u79cd\u5f3a\u5927\u529f\u80fd&#xff0c;\u5141\u8bb8\u6839\u636e\u8fd0\u884c\u65f6\u6761\u4ef6\u52a8\u6001\u751f\u6210 SQL \u8bed\u53e5\u7247\u6bb5\u3002\u4ee5\u4e0b\u662f\u5e38\u7528\u6807\u7b7e\u7684\u8be6\u7ec6\u8bf4\u660e\u548c\u4f7f\u7528\u793a\u4f8b&#xff1a;<\/p>\n<h5>&lt;if&gt; \u6807\u7b7e<\/h5>\n<p>\u7528\u4e8e\u6761\u4ef6\u5224\u65ad&#xff0c;\u6839\u636e\u6761\u4ef6\u52a8\u6001\u5305\u542b SQL \u7247\u6bb5\u3002\u793a\u4f8b&#xff1a;<\/p>\n<p>&lt;select id&#061;&#034;findUsers&#034; resultType&#061;&#034;User&#034;&gt;<br \/>\n  SELECT * FROM users<br \/>\n  WHERE 1&#061;1<br \/>\n  &lt;if test&#061;&#034;name !&#061; null&#034;&gt;<br \/>\n    AND name &#061; #{name}<br \/>\n  &lt;\/if&gt;<br \/>\n  &lt;if test&#061;&#034;age !&#061; null&#034;&gt;<br \/>\n    AND age &#061; #{age}<br \/>\n  &lt;\/if&gt;<br \/>\n&lt;\/select&gt;<\/p>\n<h5>&lt;where&gt; \u6807\u7b7e<\/h5>\n<p>\u81ea\u52a8\u5904\u7406 WHERE \u5b50\u53e5\u4e2d\u7684 AND\/OR \u5173\u952e\u5b57&#xff0c;\u907f\u514d\u8bed\u6cd5\u9519\u8bef\u3002\u793a\u4f8b&#xff1a;<\/p>\n<p>&lt;select id&#061;&#034;findUsers&#034; resultType&#061;&#034;User&#034;&gt;<br \/>\n  SELECT * FROM users<br \/>\n  &lt;where&gt;<br \/>\n    &lt;if test&#061;&#034;name !&#061; null&#034;&gt;<br \/>\n      AND name &#061; #{name}<br \/>\n    &lt;\/if&gt;<br \/>\n    &lt;if test&#061;&#034;age !&#061; null&#034;&gt;<br \/>\n      AND age &#061; #{age}<br \/>\n    &lt;\/if&gt;<br \/>\n  &lt;\/where&gt;<br \/>\n&lt;\/select&gt;<\/p>\n<h5>&lt;set&gt; \u6807\u7b7e<\/h5>\n<p>\u7528\u4e8e UPDATE \u8bed\u53e5&#xff0c;\u81ea\u52a8\u5904\u7406 SET \u5b50\u53e5\u4e2d\u7684\u9017\u53f7\u5206\u9694\u3002\u793a\u4f8b&#xff1a;<\/p>\n<p>&lt;update id&#061;&#034;updateUser&#034;&gt;<br \/>\n  UPDATE users<br \/>\n  &lt;set&gt;<br \/>\n    &lt;if test&#061;&#034;name !&#061; null&#034;&gt;<br \/>\n      name &#061; #{name},<br \/>\n    &lt;\/if&gt;<br \/>\n    &lt;if test&#061;&#034;age !&#061; null&#034;&gt;<br \/>\n      age &#061; #{age},<br \/>\n    &lt;\/if&gt;<br \/>\n  &lt;\/set&gt;<br \/>\n  WHERE id &#061; #{id}<br \/>\n&lt;\/update&gt;<\/p>\n<h5>&lt;foreach&gt; \u6807\u7b7e<\/h5>\n<p>\u904d\u5386\u96c6\u5408&#xff0c;\u5e38\u7528\u4e8e IN \u6761\u4ef6\u6216\u6279\u91cf\u63d2\u5165\u3002\u793a\u4f8b&#xff1a;<\/p>\n<p>&lt;select id&#061;&#034;findUsersByIds&#034; resultType&#061;&#034;User&#034;&gt;<br \/>\n  SELECT * FROM users<br \/>\n  WHERE id IN<br \/>\n  &lt;foreach item&#061;&#034;id&#034; collection&#061;&#034;ids&#034; open&#061;&#034;(&#034; separator&#061;&#034;,&#034; close&#061;&#034;)&#034;&gt;<br \/>\n    #{id}<br \/>\n  &lt;\/foreach&gt;<br \/>\n&lt;\/select&gt;<\/p>\n<h5>&lt;choose&gt; &lt;when&gt; &lt;otherwise&gt; \u6807\u7b7e<\/h5>\n<p>\u5b9e\u73b0\u591a\u6761\u4ef6\u5206\u652f\u9009\u62e9&#xff0c;\u7c7b\u4f3c Java \u7684 switch-case \u7ed3\u6784\u3002\u793a\u4f8b:<\/p>\n<p>&lt;select id&#061;&#034;findUsers&#034; resultType&#061;&#034;User&#034;&gt;<br \/>\n  SELECT * FROM users<br \/>\n  &lt;where&gt;<br \/>\n    &lt;choose&gt;<br \/>\n      &lt;when test&#061;&#034;name !&#061; null&#034;&gt;<br \/>\n        AND name &#061; #{name}<br \/>\n      &lt;\/when&gt;<br \/>\n      &lt;when test&#061;&#034;email !&#061; null&#034;&gt;<br \/>\n        AND email &#061; #{email}<br \/>\n      &lt;\/when&gt;<br \/>\n      &lt;otherwise&gt;<br \/>\n        AND status &#061; &#039;ACTIVE&#039;<br \/>\n      &lt;\/otherwise&gt;<br \/>\n    &lt;\/choose&gt;<br \/>\n  &lt;\/where&gt;<br \/>\n&lt;\/select&gt;<\/p>\n<h5>&lt;trim&gt; \u6807\u7b7e<\/h5>\n<p>\u63d0\u4f9b\u66f4\u7075\u6d3b\u7684 SQL \u7247\u6bb5\u62fc\u63a5\u63a7\u5236&#xff0c;\u53ef\u81ea\u5b9a\u4e49\u524d\u7f00\u3001\u540e\u7f00\u548c\u5206\u9694\u7b26\u5904\u7406\u3002\u793a\u4f8b&#xff1a;<\/p>\n<p>&lt;select id&#061;&#034;findUsers&#034; resultType&#061;&#034;User&#034;&gt;<br \/>\n  SELECT * FROM users<br \/>\n  &lt;trim prefix&#061;&#034;WHERE&#034; prefixOverrides&#061;&#034;AND |OR &#034;&gt;<br \/>\n    &lt;if test&#061;&#034;name !&#061; null&#034;&gt;<br \/>\n      AND name &#061; #{name}<br \/>\n    &lt;\/if&gt;<br \/>\n    &lt;if test&#061;&#034;age !&#061; null&#034;&gt;<br \/>\n      OR age &#061; #{age}<br \/>\n    &lt;\/if&gt;<br \/>\n  &lt;\/trim&gt;<br \/>\n&lt;\/select&gt;<\/p>\n<h5>&lt;bind&gt; \u6807\u7b7e<\/h5>\n<p>\u5b9a\u4e49\u53d8\u91cf\u5e76\u8d4b\u503c&#xff0c;\u901a\u5e38\u7528\u4e8e\u7b80\u5316\u590d\u6742\u8868\u8fbe\u5f0f\u6216\u517c\u5bb9\u4e0d\u540c\u6570\u636e\u5e93\u8bed\u6cd5\u3002\u793a\u4f8b&#xff1a;<\/p>\n<p>&lt;select id&#061;&#034;findUsers&#034; resultType&#061;&#034;User&#034;&gt;<br \/>\n  &lt;bind name&#061;&#034;pattern&#034; value&#061;&#034;&#039;%&#039; &#043; name &#043; &#039;%&#039;&#034; \/&gt;<br \/>\n  SELECT * FROM users<br \/>\n  WHERE name LIKE #{pattern}<br \/>\n&lt;\/select&gt;<\/p>\n<h2 id=\"Ou4P-1754918683511\" style=\"text-align:justify\">\u56db\u3001# $\u7684\u53d6\u503c\u548c\u53d6\u53c2\u6570\u7684\u533a\u522b,\u5206\u522b\u7528\u5728\u4ec0\u4e48\u5730\u65b9?<\/h2>\n<h3 style=\"text-align:left\"><span style=\"color:#000000\">4.1#{}<\/span><\/h3>\n<ul style=\"margin-left:0;margin-right:0\">\n<li style=\"text-align:left\"><span style=\"color:#000000\">\u539f\u7406<\/span>&#xff1a;\u9884\u7f16\u8bd1\u5904\u7406&#xff0c;\u5c06\u53c2\u6570\u66ff\u6362\u4e3a\u00a0<span style=\"color:#000000\">?<\/span>&#xff0c;\u901a\u8fc7 PreparedStatement \u6267\u884c&#xff0c;\u9632\u6b62 SQL \u6ce8\u5165\u3002<\/li>\n<li style=\"text-align:left\"><span style=\"color:#000000\">\u53d6\u503c\u65b9\u5f0f<\/span>&#xff1a;\u4f1a\u81ea\u52a8\u6839\u636e\u53c2\u6570\u7c7b\u578b\u6dfb\u52a0\u5f15\u53f7&#xff08;\u5982\u5b57\u7b26\u4e32\u52a0\u5355\u5f15\u53f7&#xff09;\u3002<\/li>\n<li style=\"text-align:left\"><span style=\"color:#000000\">\u9002\u7528\u573a\u666f<\/span>&#xff1a;\u5927\u591a\u6570\u53c2\u6570\u4f20\u9012&#xff0c;\u5982\u67e5\u8be2\u6761\u4ef6\u3001\u65b0\u589e \/ \u4fee\u6539\u7684\u5b57\u6bb5\u503c\u7b49\u3002<\/li>\n<\/ul>\n<p>&lt;!&#8211; #{}\u793a\u4f8b &#8211; \u5b89\u5168\u7684\u53c2\u6570\u4f20\u9012 &#8211;&gt;<br \/>\n&lt;select id&#061;&#034;getUserByName&#034; parameterType&#061;&#034;java.lang.String&#034; resultMap&#061;&#034;BaseResultMap&#034;&gt;<br \/>\n    SELECT id, name, age, email FROM user WHERE name &#061; #{name}<br \/>\n    &lt;!&#8211; \u4f1a\u88ab\u9884\u7f16\u8bd1\u4e3a: SELECT * FROM user WHERE name &#061; ? &#8211;&gt;<br \/>\n&lt;\/select&gt;<\/p>\n<h3>4.2${}<\/h3>\n<ul style=\"margin-left:0;margin-right:0\">\n<li style=\"text-align:left\"><span style=\"color:#000000\">\u539f\u7406<\/span>&#xff1a;\u5b57\u7b26\u4e32\u62fc\u63a5&#xff0c;\u76f4\u63a5\u5c06\u53c2\u6570\u5d4c\u5165 SQL \u8bed\u53e5&#xff0c;\u4e0d\u505a\u9884\u7f16\u8bd1&#xff0c;\u6709 SQL \u6ce8\u5165\u98ce\u9669\u3002<\/li>\n<li style=\"text-align:left\"><span style=\"color:#000000\">\u53d6\u503c\u65b9\u5f0f<\/span>&#xff1a;\u4e0d\u4f1a\u6dfb\u52a0\u5f15\u53f7&#xff0c;\u9002\u7528\u4e8e\u52a8\u6001\u62fc\u63a5\u8868\u540d\u3001\u5217\u540d\u7b49\u3002<\/li>\n<li style=\"text-align:left\"><span style=\"color:#000000\">\u9002\u7528\u573a\u666f<\/span>&#xff1a;\u52a8\u6001 SQL \u7247\u6bb5&#xff08;\u5982\u8868\u540d\u3001\u6392\u5e8f\u5b57\u6bb5&#xff09;&#xff0c;\u9700\u786e\u4fdd\u53c2\u6570\u5b89\u5168&#xff08;\u907f\u514d\u7528\u6237\u8f93\u5165&#xff09;\u3002<\/li>\n<li style=\"text-align:left\"><span style=\"color:#000000\">\u793a\u4f8b<\/span>&#xff1a;<\/li>\n<\/ul>\n<p>&lt;!&#8211; ${}\u793a\u4f8b &#8211; \u52a8\u6001\u8868\u540d &#8211;&gt;<br \/>\n&lt;select id&#061;&#034;findUsersByTableName&#034; parameterType&#061;&#034;java.lang.String&#034; resultMap&#061;&#034;BaseResultMap&#034;&gt;<br \/>\n    SELECT id, name, age, email FROM ${tableName}<br \/>\n    &lt;!&#8211; \u4f1a\u76f4\u63a5\u62fc\u63a5\u5b57\u7b26\u4e32&#xff0c;\u5982\u53c2\u6570\u4e3a&#034;user_2025&#034;&#xff0c;\u5219SQL\u4e3a: SELECT * FROM user_2025 &#8211;&gt;<br \/>\n&lt;\/select&gt;<\/p>\n<p>&lt;!&#8211; \u52a8\u6001\u6392\u5e8f\u5b57\u6bb5 &#8211;&gt;<br \/>\n&lt;select id&#061;&#034;findUsersWithOrder&#034; parameterType&#061;&#034;java.util.Map&#034; resultMap&#061;&#034;BaseResultMap&#034;&gt;<br \/>\n    SELECT id, name, age, email FROM user<br \/>\n    ORDER BY ${orderByColumn} ${orderType}<br \/>\n&lt;\/select&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb115\u6b21\u3002MyBatis \u662f\u4e00\u6b3e\u4f18\u79c0\u7684\u6301\u4e45\u5c42\u6846\u67b6\uff0c\u5b83\u652f\u6301\u81ea\u5b9a\u4e49 SQL\u3001\u5b58\u50a8\u8fc7\u7a0b\u4ee5\u53ca\u9ad8\u7ea7\u6620\u5c04\u3002MyBatis \u514d\u9664\u4e86\u51e0\u4e4e\u6240\u6709\u7684 JDBC \u4ee3\u7801\u4ee5\u53ca\u8bbe\u7f6e\u53c2\u6570\u548c\u83b7\u53d6\u7ed3\u679c\u96c6\u7684\u5de5\u4f5c\u3002Mybatis\u662f\u4e00\u4e2a\u534aORM\uff08\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04\uff09\u6846\u67b6\uff0c\u5b83JDBC\uff0c\u5f00\u53d1\u8005\u5f00\u53d1\u65f6\u53ea\u9700\u8981\u5173\u6ce8\u5982\u4f55\u7f16\u5199SQL\u8bed\u53e5\uff0c\u53ef\u4ee5\u4e25\u683c\u63a7\u5236sql\u6267\u884c\u6027\u80fd\uff0c\u7075\u6d3b\u5ea6\u9ad8\u3002\u901a\u8fc7xml\u6587\u4ef6\u6216\u6ce8\u89e3\u7684\u65b9\u5f0f\u5c06\u8981\u6267\u884c\u7684\u5404\u79cdstatement\u914d\u7f6e\u8d77\u6765\uff0c\u5e76\u901a\u8fc7java\u5bf9\u8c61\u548cstatement\u4e2dsql\u7684\u52a8\u6001\u53c2\u6570\u8fdb\u884c\u6620\u5c04\u751f\u6210\u6700\u7ec8\u6267\u884c\u7684sql\u8bed\u53e5\uff0c\u6700\u540e\u7531\u3002<\/p>\n","protected":false},"author":2,"featured_media":52929,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,1769,100,305],"topic":[],"class_list":["post-52930","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-mybatis","tag-100","tag-305"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>MyBatis\u76f8\u5173\u77e5\u8bc6\u70b9\u603b\u7ed3 - \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\/52930.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MyBatis\u76f8\u5173\u77e5\u8bc6\u70b9\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb115\u6b21\u3002MyBatis \u662f\u4e00\u6b3e\u4f18\u79c0\u7684\u6301\u4e45\u5c42\u6846\u67b6\uff0c\u5b83\u652f\u6301\u81ea\u5b9a\u4e49 SQL\u3001\u5b58\u50a8\u8fc7\u7a0b\u4ee5\u53ca\u9ad8\u7ea7\u6620\u5c04\u3002MyBatis \u514d\u9664\u4e86\u51e0\u4e4e\u6240\u6709\u7684 JDBC \u4ee3\u7801\u4ee5\u53ca\u8bbe\u7f6e\u53c2\u6570\u548c\u83b7\u53d6\u7ed3\u679c\u96c6\u7684\u5de5\u4f5c\u3002Mybatis\u662f\u4e00\u4e2a\u534aORM\uff08\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04\uff09\u6846\u67b6\uff0c\u5b83JDBC\uff0c\u5f00\u53d1\u8005\u5f00\u53d1\u65f6\u53ea\u9700\u8981\u5173\u6ce8\u5982\u4f55\u7f16\u5199SQL\u8bed\u53e5\uff0c\u53ef\u4ee5\u4e25\u683c\u63a7\u5236sql\u6267\u884c\u6027\u80fd\uff0c\u7075\u6d3b\u5ea6\u9ad8\u3002\u901a\u8fc7xml\u6587\u4ef6\u6216\u6ce8\u89e3\u7684\u65b9\u5f0f\u5c06\u8981\u6267\u884c\u7684\u5404\u79cdstatement\u914d\u7f6e\u8d77\u6765\uff0c\u5e76\u901a\u8fc7java\u5bf9\u8c61\u548cstatement\u4e2dsql\u7684\u52a8\u6001\u53c2\u6570\u8fdb\u884c\u6620\u5c04\u751f\u6210\u6700\u7ec8\u6267\u884c\u7684sql\u8bed\u53e5\uff0c\u6700\u540e\u7531\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/52930.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-11T13:39:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250811133910-6899f27e92f9f.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\/52930.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/52930.html\",\"name\":\"MyBatis\u76f8\u5173\u77e5\u8bc6\u70b9\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-11T13:39:12+00:00\",\"dateModified\":\"2025-08-11T13:39:12+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/52930.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/52930.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/52930.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MyBatis\u76f8\u5173\u77e5\u8bc6\u70b9\u603b\u7ed3\"}]},{\"@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\u76f8\u5173\u77e5\u8bc6\u70b9\u603b\u7ed3 - \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\/52930.html","og_locale":"zh_CN","og_type":"article","og_title":"MyBatis\u76f8\u5173\u77e5\u8bc6\u70b9\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb115\u6b21\u3002MyBatis \u662f\u4e00\u6b3e\u4f18\u79c0\u7684\u6301\u4e45\u5c42\u6846\u67b6\uff0c\u5b83\u652f\u6301\u81ea\u5b9a\u4e49 SQL\u3001\u5b58\u50a8\u8fc7\u7a0b\u4ee5\u53ca\u9ad8\u7ea7\u6620\u5c04\u3002MyBatis \u514d\u9664\u4e86\u51e0\u4e4e\u6240\u6709\u7684 JDBC \u4ee3\u7801\u4ee5\u53ca\u8bbe\u7f6e\u53c2\u6570\u548c\u83b7\u53d6\u7ed3\u679c\u96c6\u7684\u5de5\u4f5c\u3002Mybatis\u662f\u4e00\u4e2a\u534aORM\uff08\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04\uff09\u6846\u67b6\uff0c\u5b83JDBC\uff0c\u5f00\u53d1\u8005\u5f00\u53d1\u65f6\u53ea\u9700\u8981\u5173\u6ce8\u5982\u4f55\u7f16\u5199SQL\u8bed\u53e5\uff0c\u53ef\u4ee5\u4e25\u683c\u63a7\u5236sql\u6267\u884c\u6027\u80fd\uff0c\u7075\u6d3b\u5ea6\u9ad8\u3002\u901a\u8fc7xml\u6587\u4ef6\u6216\u6ce8\u89e3\u7684\u65b9\u5f0f\u5c06\u8981\u6267\u884c\u7684\u5404\u79cdstatement\u914d\u7f6e\u8d77\u6765\uff0c\u5e76\u901a\u8fc7java\u5bf9\u8c61\u548cstatement\u4e2dsql\u7684\u52a8\u6001\u53c2\u6570\u8fdb\u884c\u6620\u5c04\u751f\u6210\u6700\u7ec8\u6267\u884c\u7684sql\u8bed\u53e5\uff0c\u6700\u540e\u7531\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/52930.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-11T13:39:12+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250811133910-6899f27e92f9f.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\/52930.html","url":"https:\/\/www.wsisp.com\/helps\/52930.html","name":"MyBatis\u76f8\u5173\u77e5\u8bc6\u70b9\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-11T13:39:12+00:00","dateModified":"2025-08-11T13:39:12+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/52930.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/52930.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/52930.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"MyBatis\u76f8\u5173\u77e5\u8bc6\u70b9\u603b\u7ed3"}]},{"@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\/52930","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=52930"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/52930\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/52929"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=52930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=52930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=52930"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=52930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}