{"id":80279,"date":"2026-03-04T21:01:26","date_gmt":"2026-03-04T13:01:26","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/80279.html"},"modified":"2026-03-04T21:01:26","modified_gmt":"2026-03-04T13:01:26","slug":"mybatis-%e4%bb%8e%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/80279.html","title":{"rendered":"MyBatis \u4ece\u5165\u95e8\u5230\u7cbe\u901a"},"content":{"rendered":"<h3>\u4e00\u3001MyBatis \u6838\u5fc3\u4ecb\u7ecd<\/h3>\n<h4>1.1 \u4ec0\u4e48\u662f\u6846\u67b6<\/h4>\n<p>\u6846\u67b6&#xff08;Framework&#xff09;\u662f\u8f6f\u4ef6\u5f00\u53d1\u7684 &#034;\u534a\u6210\u54c1&#034;&#xff0c;\u5b83\u5c01\u88c5\u4e86\u57fa\u7840\u4ee3\u7801\u5e76\u63d0\u4f9b\u6807\u51c6\u5316 API&#xff0c;\u5f00\u53d1\u8005\u57fa\u4e8e\u6846\u67b6\u5f00\u53d1\u53ef\u7701\u53bb\u91cd\u590d\u7f16\u7801\u5de5\u4f5c&#xff0c;\u5927\u5e45\u63d0\u5347\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<p>\u5982\u679c\u628a\u6210\u54c1\u8f6f\u4ef6\u6bd4\u4f5c\u88c5\u4fee\u597d\u7684\u65b0\u623f&#xff0c;\u6846\u67b6\u5c31\u50cf\u6bdb\u576f\u623f \u2014\u2014 \u63d0\u4f9b\u57fa\u7840\u7ed3\u6784&#xff0c;\u4fdd\u8bc1\u6838\u5fc3\u8d28\u91cf&#xff0c;\u5f00\u53d1\u8005\u53ea\u9700\u4e13\u6ce8\u4e8e\u4e1a\u52a1\u903b\u8f91&#xff08;\u88c5\u4fee&#xff09;\u5373\u53ef\u3002<\/p>\n<h4>1.2 \u6846\u67b6\u8981\u89e3\u51b3\u7684\u6838\u5fc3\u95ee\u9898<\/h4>\n<p>\u6846\u67b6\u6700\u6838\u5fc3\u7684\u4ef7\u503c\u662f\u6280\u672f\u6574\u5408\u4e0e\u89e3\u8026\u3002\u5728 J2EE \u4f53\u7cfb\u4e2d&#xff0c;\u6280\u672f\u9009\u578b\u591a\u6837\u4e14\u590d\u6742&#xff0c;\u6846\u67b6\u80fd\u5c06\u5e94\u7528\u8bbe\u8ba1\u4e0e\u5e95\u5c42\u6280\u672f\u5b9e\u73b0\u5206\u79bb&#xff0c;\u8ba9\u7814\u53d1\u805a\u7126\u4e8e\u4e1a\u52a1\u8bbe\u8ba1&#xff0c;\u800c\u975e\u6280\u672f\u7ec6\u8282\u3002<\/p>\n<h4>1.3 \u4f20\u7edf JDBC \u7684\u75db\u70b9<\/h4>\n<p>\u5148\u770b\u4e00\u6bb5\u4f20\u7edf JDBC \u4ee3\u7801&#xff1a;<\/p>\n<p>public class JdbcTest {<br \/>\n    public static void main(String[] args) {<br \/>\n        try {<br \/>\n            \/\/1.\u52a0\u8f7d\u6570\u636e\u5e93\u9a71\u52a8<br \/>\n            Class.forName(&#034;com.mysql.jdbc.Driver&#034;);<br \/>\n            \/\/2.\u521b\u5efa\u8fde\u63a5\u5bf9\u8c61<br \/>\n            String url &#061; &#034;jdbc:mysql:\/\/192.168.10.137:3306\/ssm&#034;;<br \/>\n            Connection connection &#061; DriverManager.getConnection(url, &#034;root&#034;, &#034;1111&#034;);<br \/>\n            String sql &#061; &#034;select * from account&#034;;<br \/>\n            \/\/3.\u51c6\u5907PreparedStatement\u5bf9\u8c61<br \/>\n            PreparedStatement pst &#061; connection.prepareStatement(sql);<br \/>\n            \/\/4.\u6267\u884csql\u8bed\u53e5<br \/>\n            ResultSet rs &#061; pst.executeQuery();<br \/>\n            \/\/5.\u904d\u5386\u7ed3\u679c\u96c6<br \/>\n            while(rs.next()){<br \/>\n                Integer id &#061; rs.getInt(&#034;id&#034;);<br \/>\n                String name &#061; rs.getString(&#034;name&#034;);<br \/>\n                Double money &#061; rs.getDouble(&#034;money&#034;);<br \/>\n                System.out.println(id &#043; &#034; &#034; &#043; name &#043; &#034; &#034; &#043; money);<br \/>\n            }<br \/>\n            \/\/6.\u5173\u95ed\u8d44\u6e90<br \/>\n            rs.close();<br \/>\n            pst.close();<br \/>\n            connection.close();<br \/>\n        } catch (Exception e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>\u4f20\u7edf JDBC \u5b58\u5728\u4e09\u5927\u6838\u5fc3\u95ee\u9898&#xff1a;<\/p>\n<ul>\n<li>\u624b\u52a8\u521b\u5efa \/ \u91ca\u653e\u6570\u636e\u5e93\u8fde\u63a5&#xff0c;\u8d44\u6e90\u7ba1\u7406\u7e41\u7410<\/li>\n<li>SQL \u8bed\u53e5\u786c\u7f16\u7801\u5728\u4ee3\u7801\u4e2d&#xff0c;\u7ef4\u62a4\u6210\u672c\u9ad8<\/li>\n<li>\u7ed3\u679c\u96c6\u89e3\u6790\u91cd\u590d\u4e14\u5197\u4f59&#xff0c;\u4ee3\u7801\u590d\u7528\u6027\u5dee<\/li>\n<\/ul>\n<h4>1.4 MyBatis \u6846\u67b6\u6982\u8ff0<\/h4>\n<p>MyBatis \u662f\u4e00\u6b3e\u4f18\u79c0\u7684\u6301\u4e45\u5c42\u6846\u67b6&#xff0c;\u5b83\u5bf9 JDBC \u8fdb\u884c\u5c01\u88c5&#xff0c;\u8ba9\u5f00\u53d1\u8005\u53ea\u9700\u5173\u6ce8 SQL \u672c\u8eab&#xff0c;\u65e0\u9700\u5904\u7406\u6ce8\u518c\u9a71\u52a8\u3001\u521b\u5efa\u8fde\u63a5\u3001\u53c2\u6570\u8bbe\u7f6e\u3001\u7ed3\u679c\u96c6\u89e3\u6790\u7b49\u7e41\u7410\u64cd\u4f5c\u3002<\/p>\n<p>MyBatis \u524d\u8eab\u662f Apache \u7684 iBatis&#xff0c;2010 \u5e74\u8fc1\u79fb\u81f3 Google Code \u5e76\u66f4\u540d&#xff0c;\u6838\u5fc3\u5b9a\u4f4d\u662f\u7b80\u5316\u6570\u636e\u5e93\u64cd\u4f5c&#xff0c;\u4e13\u6ce8 SQL \u5c42\u5f00\u53d1\u3002<\/p>\n<h3>\u4e8c\u3001MyBatis \u5165\u95e8\u6848\u4f8b<\/h3>\n<h4>2.1 \u73af\u5883\u51c6\u5907<\/h4>\n<h5>&#xff08;1&#xff09;Maven \u4f9d\u8d56\u914d\u7f6e&#xff08;pom.xml&#xff09;<\/h5>\n<p>&lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;UTF-8&#034;?&gt;<br \/>\n&lt;project xmlns&#061;&#034;http:\/\/maven.apache.org\/POM\/4.0.0&#034;<br \/>\n         xmlns:xsi&#061;&#034;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#034;<br \/>\n         xsi:schemaLocation&#061;&#034;http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd&#034;&gt;<br \/>\n    &lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;<\/p>\n<p>    &lt;groupId&gt;com.hg&lt;\/groupId&gt;<br \/>\n    &lt;artifactId&gt;01_mybatis_HelloWorld&lt;\/artifactId&gt;<br \/>\n    &lt;version&gt;1.0-SNAPSHOT&lt;\/version&gt;<\/p>\n<p>    &lt;properties&gt;<br \/>\n        &lt;project.build.sourceEncoding&gt;UTF-8&lt;\/project.build.sourceEncoding&gt;<br \/>\n        &lt;project.reporting.outputEncoding&gt;UTF-8&lt;\/project.reporting.outputEncoding&gt;<br \/>\n        &lt;maven.compiler.source&gt;8&lt;\/maven.compiler.source&gt;<br \/>\n        &lt;maven.compiler.target&gt;8&lt;\/maven.compiler.target&gt;<br \/>\n    &lt;\/properties&gt;<\/p>\n<p>    &lt;dependencies&gt;<br \/>\n        &lt;!&#8211; MyBatis\u6838\u5fc3\u4f9d\u8d56 &#8211;&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;org.mybatis&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;mybatis&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;3.4.5&lt;\/version&gt;<br \/>\n        &lt;\/dependency&gt;<br \/>\n        &lt;!&#8211; MySQL\u9a71\u52a8 &#8211;&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;mysql&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;mysql-connector-java&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;5.1.47&lt;\/version&gt;<br \/>\n        &lt;\/dependency&gt;<br \/>\n        &lt;!&#8211; \u65e5\u5fd7\u4f9d\u8d56 &#8211;&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;log4j&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;log4j&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;1.2.17&lt;\/version&gt;<br \/>\n        &lt;\/dependency&gt;<br \/>\n        &lt;!&#8211; \u5355\u5143\u6d4b\u8bd5 &#8211;&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;junit&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;junit&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;4.12&lt;\/version&gt;<br \/>\n        &lt;\/dependency&gt;<br \/>\n    &lt;\/dependencies&gt;<\/p>\n<p>    &lt;build&gt;<br \/>\n        &lt;!&#8211; \u52a0\u8f7djava\u76ee\u5f55\u4e0b\u7684xml\u914d\u7f6e\u6587\u4ef6 &#8211;&gt;<br \/>\n        &lt;resources&gt;<br \/>\n            &lt;resource&gt;<br \/>\n                &lt;directory&gt;src\/main\/java&lt;\/directory&gt;<br \/>\n                &lt;includes&gt;<br \/>\n                    &lt;include&gt;**\/*.xml&lt;\/include&gt;<br \/>\n                &lt;\/includes&gt;<br \/>\n            &lt;\/resource&gt;<br \/>\n        &lt;\/resources&gt;<br \/>\n    &lt;\/build&gt;<br \/>\n&lt;\/project&gt;<\/p>\n<h5>&#xff08;2&#xff09;\u65e5\u5fd7\u914d\u7f6e&#xff08;log4j.properties&#xff09;<\/h5>\n<p>properties<\/p>\n<p># Global logging configuration<br \/>\nlog4j.rootLogger&#061;DEBUG, stdout<br \/>\n# Console output<br \/>\nlog4j.appender.stdout&#061;org.apache.log4j.ConsoleAppender<br \/>\nlog4j.appender.stdout.layout&#061;org.apache.log4j.PatternLayout<br \/>\nlog4j.appender.stdout.layout.ConversionPattern&#061;%5p [%t] &#8211; %m%n<\/p>\n<h4>2.2 \u6838\u5fc3\u4ee3\u7801\u5b9e\u73b0<\/h4>\n<h5>&#xff08;1&#xff09;\u5b9e\u4f53\u7c7b&#xff08;User.java&#xff09;<\/h5>\n<p>public class User implements Serializable {<br \/>\n    private Integer id;<br \/>\n    private String username;<br \/>\n    private Date birthday;<br \/>\n    private String sex;<br \/>\n    private String address;<\/p>\n<p>    \/\/ Getter &amp; Setter<br \/>\n    public Integer getId() { return id; }<br \/>\n    public void setId(Integer id) { this.id &#061; id; }<br \/>\n    public String getUsername() { return username; }<br \/>\n    public void setUsername(String username) { this.username &#061; username; }<br \/>\n    public Date getBirthday() { return birthday; }<br \/>\n    public void setBirthday(Date birthday) { this.birthday &#061; birthday; }<br \/>\n    public String getSex() { return sex; }<br \/>\n    public void setSex(String sex) { this.sex &#061; sex; }<br \/>\n    public String getAddress() { return address; }<br \/>\n    public void setAddress(String address) { this.address &#061; address; }<\/p>\n<p>    &#064;Override<br \/>\n    public String toString() {<br \/>\n        return &#034;User{&#034; &#043;<br \/>\n                &#034;id&#061;&#034; &#043; id &#043;<br \/>\n                &#034;, username&#061;&#039;&#034; &#043; username &#043; &#039;\\\\&#039;&#039; &#043;<br \/>\n                &#034;, birthday&#061;&#034; &#043; birthday &#043;<br \/>\n                &#034;, sex&#061;&#039;&#034; &#043; sex &#043; &#039;\\\\&#039;&#039; &#043;<br \/>\n                &#034;, address&#061;&#039;&#034; &#043; address &#043; &#039;\\\\&#039;&#039; &#043;<br \/>\n                &#039;}&#039;;<br \/>\n    }<br \/>\n}<\/p>\n<h5>&#xff08;2&#xff09;DAO \u63a5\u53e3&#xff08;UserMapper.java&#xff09;<\/h5>\n<p>public interface UserMapper {<br \/>\n    \/**<br \/>\n     * \u67e5\u8be2\u6240\u6709\u7528\u6237<br \/>\n     * &#064;return \u7528\u6237\u5217\u8868<br \/>\n     *\/<br \/>\n    public List&lt;User&gt; findAll();<br \/>\n}<\/p>\n<h5>&#xff08;3&#xff09;Mapper \u6620\u5c04\u6587\u4ef6&#xff08;UserMapper.xml&#xff09;<\/h5>\n<p>&lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;UTF-8&#034;?&gt;<br \/>\n&lt;!DOCTYPE mapper<br \/>\n        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; namespace&#xff1a;\u63a5\u53e3\u5168\u7c7b\u540d &#8211;&gt;<br \/>\n&lt;mapper namespace&#061;&#034;com.hg.dao.UserMapper&#034;&gt;<br \/>\n    &lt;!&#8211;<br \/>\n        id&#xff1a;\u63a5\u53e3\u65b9\u6cd5\u540d<br \/>\n        resultType&#xff1a;\u8fd4\u56de\u503c\u7c7b\u578b<br \/>\n     &#8211;&gt;<br \/>\n    &lt;select id&#061;&#034;findAll&#034; resultType&#061;&#034;com.hg.pojo.User&#034;&gt;<br \/>\n        select * from user<br \/>\n    &lt;\/select&gt;<br \/>\n&lt;\/mapper&gt;<\/p>\n<h5>&#xff08;4&#xff09;MyBatis \u6838\u5fc3\u914d\u7f6e&#xff08;mybatis-config.xml&#xff09;<\/h5>\n<p>&lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;UTF-8&#034;?&gt;<br \/>\n&lt;!DOCTYPE configuration PUBLIC &#034;-\/\/mybatis.org\/\/DTD Config 3.0\/\/EN&#034; &#034;http:\/\/mybatis.org\/dtd\/mybatis-3-config.dtd&#034;&gt;<br \/>\n&lt;configuration&gt;<br \/>\n    &lt;!&#8211; \u73af\u5883\u914d\u7f6e &#8211;&gt;<br \/>\n    &lt;environments default&#061;&#034;dev&#034;&gt;<br \/>\n        &lt;environment id&#061;&#034;dev&#034;&gt;<br \/>\n            &lt;!&#8211; \u4e8b\u52a1\u7ba1\u7406&#xff1a;JDBC\u539f\u751f\u4e8b\u52a1 &#8211;&gt;<br \/>\n            &lt;transactionManager type&#061;&#034;JDBC&#034;&gt;&lt;\/transactionManager&gt;<br \/>\n            &lt;!&#8211; \u6570\u636e\u6e90&#xff1a;\u8fde\u63a5\u6c60 &#8211;&gt;<br \/>\n            &lt;dataSource type&#061;&#034;POOLED&#034;&gt;<br \/>\n                &lt;property name&#061;&#034;driver&#034; value&#061;&#034;com.mysql.jdbc.Driver&#034;\/&gt;<br \/>\n                &lt;property name&#061;&#034;url&#034; value&#061;&#034;jdbc:mysql:\/\/127.0.0.1:3306\/mybatis?useSSL&#061;false&amp;amp;serverTimezone&#061;Asia\/Shanghai&amp;amp;characterEncoding&#061;UTF-8&#034;\/&gt;<br \/>\n                &lt;property name&#061;&#034;username&#034; value&#061;&#034;root&#034;\/&gt;<br \/>\n                &lt;property name&#061;&#034;password&#034; value&#061;&#034;1111&#034;\/&gt;<br \/>\n            &lt;\/dataSource&gt;<br \/>\n        &lt;\/environment&gt;<br \/>\n    &lt;\/environments&gt;<br \/>\n    &lt;!&#8211; \u52a0\u8f7dMapper\u6620\u5c04\u6587\u4ef6 &#8211;&gt;<br \/>\n    &lt;mappers&gt;<br \/>\n        &lt;mapper resource&#061;&#034;com\/hg\/dao\/UserMapper.xml&#034;\/&gt;<br \/>\n    &lt;\/mappers&gt;<br \/>\n&lt;\/configuration&gt;<\/p>\n<h4>2.3 \u6d4b\u8bd5\u4ee3\u7801<\/h4>\n<p>public class MyBatisTest {<\/p>\n<p>    private InputStream inputStream;<br \/>\n    private SqlSession sqlSession;<\/p>\n<p>    &#064;Before<br \/>\n    public void createSqlSession() throws IOException {<br \/>\n        \/\/ 1.\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6<br \/>\n        String resource &#061; &#034;mybatis-config.xml&#034;;<br \/>\n        inputStream &#061; Resources.getResourceAsStream(resource);<\/p>\n<p>        \/\/ 2.\u521b\u5efaSqlSessionFactory<br \/>\n        SqlSessionFactory sqlSessionFactory &#061; new SqlSessionFactoryBuilder().build(inputStream);<\/p>\n<p>        \/\/ 3.\u83b7\u53d6SqlSession<br \/>\n        sqlSession &#061; sqlSessionFactory.openSession();<br \/>\n    }<\/p>\n<p>    &#064;Test<br \/>\n    public void testFindAll(){<br \/>\n        \/\/ 4.\u83b7\u53d6Mapper\u4ee3\u7406\u5bf9\u8c61<br \/>\n        UserDao userDao &#061; sqlSession.getMapper(UserMapper.class);<\/p>\n<p>        \/\/ 5.\u6267\u884c\u67e5\u8be2<br \/>\n        List&lt;User&gt; userList &#061; userMapper.findAll();<\/p>\n<p>        \/\/ 6.\u8f93\u51fa\u7ed3\u679c<br \/>\n        for(User user : userList) {<br \/>\n            System.out.println(user);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    &#064;After<br \/>\n    public void closeSqlSession() throws IOException {<br \/>\n        \/\/ 7.\u91ca\u653e\u8d44\u6e90<br \/>\n        sqlSession.close();<br \/>\n        inputStream.close();<br \/>\n    }<br \/>\n}<\/p>\n<h4>2.4 MyBatis \u8fd0\u884c\u539f\u7406<\/h4>\n<p>MyBatis \u6267\u884c\u6d41\u7a0b\u6838\u5fc3 8 \u6b65&#xff1a;<\/p>\n<li>\u8bfb\u53d6\u5168\u5c40\u914d\u7f6e\u6587\u4ef6&#xff08;mybatis-config.xml&#xff09;<\/li>\n<li>\u52a0\u8f7d Mapper \u6620\u5c04\u6587\u4ef6&#xff08;SQL \u914d\u7f6e&#xff09;<\/li>\n<li>\u6784\u5efa SqlSessionFactory&#xff08;\u4f1a\u8bdd\u5de5\u5382&#xff09;<\/li>\n<li>\u521b\u5efa SqlSession&#xff08;\u6570\u636e\u5e93\u4f1a\u8bdd&#xff09;<\/li>\n<li>\u901a\u8fc7 Executor \u6267\u884c\u5668\u5904\u7406 SQL<\/li>\n<li>\u5c01\u88c5 MappedStatement&#xff08;SQL &#043; \u53c2\u6570 &#043; \u8fd4\u56de\u503c&#xff09;<\/li>\n<li>\u8f93\u5165\u53c2\u6570\u6620\u5c04&#xff08;\u66ff\u6362 SQL \u5360\u4f4d\u7b26&#xff09;<\/li>\n<li>\u8f93\u51fa\u7ed3\u679c\u6620\u5c04&#xff08;\u5c01\u88c5\u4e3a Java \u5bf9\u8c61&#xff09;<\/li>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1660\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260304130124-69a82d24e21c1.png\" width=\"711\" \/><\/p>\n<h3>\u4e09\u3001MyBatis \u6838\u5fc3 CRUD \u64cd\u4f5c<\/h3>\n<h4>3.1 \u67e5\u8be2\u64cd\u4f5c<\/h4>\n<h5>&#xff08;1&#xff09;\u5355\u4e2a\u53c2\u6570\u67e5\u8be2<\/h5>\n<p>\/\/ DAO\u63a5\u53e3<br \/>\npublic User findUserById(Integer id);<\/p>\n<p>&lt;!&#8211; Mapper\u914d\u7f6e &#8211;&gt;<br \/>\n&lt;select id&#061;&#034;findUserById&#034; parameterType&#061;&#034;java.lang.Integer&#034; resultType&#061;&#034;com.hg.pojo.User&#034;&gt;<br \/>\n    select * from user where id&#061;#{id}<br \/>\n&lt;\/select&gt;<\/p>\n<h5>&#xff08;2&#xff09;\u591a\u53c2\u6570\u67e5\u8be2<\/h5>\n<h6>\u65b9\u5f0f 1&#xff1a;\u5e8f\u53f7\u7ed1\u5b9a<\/h6>\n<p>public User findUserByIdAndName(Integer id, String username);<\/p>\n<p>&lt;select id&#061;&#034;findUserByIdAndName&#034; resultType&#061;&#034;com.hg.pojo.User&#034;&gt;<br \/>\n    SELECT * FROM user WHERE id &#061; #{arg0} AND username &#061; #{arg1}<br \/>\n    &lt;!&#8211; \u6216\u4f7f\u7528param1\/param2&#xff1a;WHERE id &#061; #{param1} AND username &#061; #{param2} &#8211;&gt;<br \/>\n&lt;\/select&gt;<\/p>\n<h6>\u65b9\u5f0f 2&#xff1a;\u6ce8\u89e3\u7ed1\u5b9a<\/h6>\n<p>public User findUserByIdAndName2(&#064;Param(&#034;id&#034;) Integer id, &#064;Param(&#034;username&#034;)String username);<\/p>\n<p>&lt;select id&#061;&#034;findUserByIdAndName2&#034; resultType&#061;&#034;com.hg.pojo.User&#034;&gt;<br \/>\n    SELECT * FROM user WHERE id &#061; #{id} AND username &#061; #{username}<br \/>\n&lt;\/select&gt;<\/p>\n<h6>\u65b9\u5f0f 3&#xff1a;\u5bf9\u8c61\u7ed1\u5b9a<\/h6>\n<p>public User findUserByUserInfo(User user);<\/p>\n<p>&lt;select id&#061;&#034;findUserByUserInfo&#034; parameterType&#061;&#034;com.hg.pojo.User&#034; resultType&#061;&#034;com.hg.pojo.User&#034;&gt;<br \/>\n    SELECT * FROM user WHERE id &#061; #{id} AND username &#061; #{username}<br \/>\n&lt;\/select&gt;<\/p>\n<h6>\u65b9\u5f0f 4&#xff1a;Map \u7ed1\u5b9a<\/h6>\n<p>public User findUserByMap(Map&lt;String, Object&gt; map);<\/p>\n<p>&lt;select id&#061;&#034;findUserByMap&#034; parameterMap&#061;&#034;java.util.Map&#034; resultType&#061;&#034;com.hg.pojo.User&#034;&gt;<br \/>\n    SELECT * FROM user WHERE id &#061; #{id} AND username &#061; #{username}<br \/>\n&lt;\/select&gt;<\/p>\n<h5>&#xff08;3&#xff09;\u6a21\u7cca\u67e5\u8be2<\/h5>\n<p>public List&lt;User&gt; findUserByName(String username);<\/p>\n<p>&lt;select id&#061;&#034;findUserByName&#034; parameterType&#061;&#034;string&#034; resultType&#061;&#034;com.hg.pojo.User&#034;&gt;<br \/>\n    &lt;!&#8211; \u63a8\u8350\u65b9\u5f0f&#xff1a;\u9632\u6b62SQL\u6ce8\u5165 &#8211;&gt;<br \/>\n    select * from user where username like concat(&#039;%&#039;,#{username},&#039;%&#039;)<br \/>\n    &lt;!&#8211; \u6216&#xff1a;select * from user where username like &#039;%${value}%&#039; &#8211;&gt;<br \/>\n&lt;\/select&gt;<\/p>\n<h5>&#xff08;4&#xff09;\u805a\u5408\u51fd\u6570\u67e5\u8be2<\/h5>\n<p>public Integer getTotal();<\/p>\n<p>&lt;select id&#061;&#034;getTotal&#034; resultType&#061;&#034;int&#034;&gt;<br \/>\n    SELECT COUNT(id) FROM user<br \/>\n&lt;\/select&gt;<\/p>\n<h4>3.2 \u5220\u9664\u64cd\u4f5c<\/h4>\n<p>public void deleteUserById(Integer id);<\/p>\n<p>&lt;delete id&#061;&#034;deleteUserById&#034; parameterType&#061;&#034;Integer&#034;&gt;<br \/>\n    DELETE FROM user WHERE id &#061; #{id}<br \/>\n&lt;\/delete&gt;<\/p>\n<p>\/\/ \u6d4b\u8bd5\u4ee3\u7801<br \/>\n&#064;Test<br \/>\npublic void testDeleteUserById(){<br \/>\n    UserDao userDao &#061; sqlSession.getMapper(UserDao.class);<br \/>\n    userDao.deleteUserById(41);<br \/>\n    sqlSession.commit(); \/\/ \u624b\u52a8\u63d0\u4ea4\u4e8b\u52a1<br \/>\n}<\/p>\n<h4>3.3 \u4fee\u6539\u64cd\u4f5c<\/h4>\n<p>public void updateUserById(User user);<\/p>\n<p>&lt;update id&#061;&#034;updateUserById&#034; parameterType&#061;&#034;com.hg.pojo.User&#034;&gt;<br \/>\n    update user set username&#061;#{username},password&#061;#{password},<br \/>\n    birthday&#061;#{birthday},sex&#061;#{sex},address&#061;#{address} where id&#061;#{id}<br \/>\n&lt;\/update&gt;<\/p>\n<p>    &#064;Test<br \/>\n    public void testUpdateUserById(){<br \/>\n        User userParam &#061; new User();<br \/>\n        userParam.setId(41);<br \/>\n        userParam.setUsername(&#034;\u5434\u5f66\u7956&#034;);<br \/>\n        userParam.setSex(&#034;\u7537&#034;);<br \/>\n        userParam.setAddress(&#034;\u4e2d\u56fd&#034;);<br \/>\n        userParam.setBirthday(new Date());<br \/>\n        userMapper.updateUserById(userParam);<br \/>\n    }<\/p>\n<h4>3.4 \u65b0\u589e\u64cd\u4f5c&#xff08;\u542b\u4e3b\u952e\u56de\u586b&#xff09;<\/h4>\n<p>public void insertUser(User user);<\/p>\n<p>&lt;insert id&#061;&#034;insertUser&#034; useGeneratedKeys&#061;&#034;true&#034; keyProperty&#061;&#034;id&#034; parameterType&#061;&#034;com.hg.pojo.User&#034;&gt;<br \/>\n    insert into user(username,password,birthday,sex,address)<br \/>\n    values(#{username},#{password},#{birthday},#{sex},#{address})<br \/>\n&lt;\/insert&gt;<\/p>\n<p>&#064;Test<br \/>\npublic void testInsertUser(){<br \/>\n    UserDao userDao &#061; sqlSession.getMapper(UserDao.class);<br \/>\n    User user &#061; new User();<br \/>\n    user.setUsername(&#034;\u5218\u5fb7\u534e&#034;);<br \/>\n    user.setPassword(&#034;111&#034;);<br \/>\n    user.setBirthday(new Date());<br \/>\n    user.setSex(&#034;\u7537&#034;);<br \/>\n    user.setAddress(&#034;\u9999\u6e2f&#034;);<br \/>\n    userDao.insertUser(user);<br \/>\n    System.out.println(&#034;\u65b0\u589e\u8bb0\u5f55\u7684id\u503c&#xff1a;&#034;&#043;user.getId()); \/\/ \u83b7\u53d6\u81ea\u589e\u4e3b\u952e<br \/>\n    sqlSession.commit();<br \/>\n}<\/p>\n<h4>3.5 #{} vs ${} \u6838\u5fc3\u533a\u522b<\/h4>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\">\n<tr>\u7279\u6027#{}${}<\/tr>\n<tbody>\n<tr>\n<td>\u672c\u8d28<\/td>\n<td>\u9884\u7f16\u8bd1\u5360\u4f4d\u7b26<\/td>\n<td>SQL \u5b57\u7b26\u4e32\u62fc\u63a5<\/td>\n<\/tr>\n<tr>\n<td>\u7c7b\u578b\u8f6c\u6362<\/td>\n<td>\u81ea\u52a8 Java\/JDBC \u7c7b\u578b\u8f6c\u6362<\/td>\n<td>\u65e0\u7c7b\u578b\u8f6c\u6362<\/td>\n<\/tr>\n<tr>\n<td>SQL \u6ce8\u5165<\/td>\n<td>\u53ef\u9632\u6b62\u6ce8\u5165<\/td>\n<td>\u5b58\u5728\u6ce8\u5165\u98ce\u9669<\/td>\n<\/tr>\n<tr>\n<td>\u53c2\u6570\u7ed1\u5b9a<\/td>\n<td>\u652f\u6301\u4efb\u610f\u53c2\u6570\u540d&#xff08;\u5355\u4e2a\u53c2\u6570\u53ef\u5199 value&#xff09;<\/td>\n<td>\u5355\u4e2a\u53c2\u6570\u53ea\u80fd\u5199 value<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u56db\u3001\u81ea\u5b9a\u4e49 MyBatis&#xff08;\u6838\u5fc3\u539f\u7406\u5256\u6790&#xff09;<\/h3>\n<h4>4.1 \u6838\u5fc3\u8bbe\u8ba1\u6a21\u5f0f<\/h4>\n<p>MyBatis \u5927\u91cf\u4f7f\u7528\u8bbe\u8ba1\u6a21\u5f0f\u7b80\u5316\u5f00\u53d1&#xff1a;<\/p>\n<ul>\n<li>\u6784\u5efa\u8005\u6a21\u5f0f&#xff1a;SqlSessionFactoryBuilder&#xff08;\u5c4f\u853d\u5bf9\u8c61\u6784\u5efa\u7ec6\u8282&#xff09;<\/li>\n<li>\u5de5\u5382\u6a21\u5f0f&#xff1a;SqlSessionFactory&#xff08;\u89e3\u8026 SqlSession \u521b\u5efa&#xff09;<\/li>\n<li>\u4ee3\u7406\u6a21\u5f0f&#xff1a;SqlSession&#xff08;\u521b\u5efa Mapper \u4ee3\u7406\u5bf9\u8c61&#xff09;<\/li>\n<\/ul>\n<h4>4.2 \u6838\u5fc3\u5bf9\u8c61\u5c01\u88c5<\/h4>\n<h5>&#xff08;1&#xff09;\u914d\u7f6e\u7c7b&#xff08;Configuration&#xff09;<\/h5>\n<p>public class Configuration {<br \/>\n    private String driver;<br \/>\n    private String url;<br \/>\n    private String username;<br \/>\n    private String password;<br \/>\n    \/\/ \u5b58\u50a8Mapper\u914d\u7f6e&#xff1a;key&#061;namespace&#043;id<br \/>\n    private Map&lt;String, MappedStatement&gt; mappers &#061; new HashMap&lt;&gt;();<\/p>\n<p>    \/\/ Getter &amp; Setter<br \/>\n}<\/p>\n<h5>&#xff08;2&#xff09;SQL \u5c01\u88c5\u7c7b&#xff08;MappedStatement&#xff09;<\/h5>\n<p>public class MappedStatement {<br \/>\n    private String queryString; \/\/ SQL\u8bed\u53e5<br \/>\n    private String resultType;  \/\/ \u8fd4\u56de\u503c\u7c7b\u578b<\/p>\n<p>    \/\/ Getter &amp; Setter<br \/>\n}<\/p>\n<h5>&#xff08;3&#xff09;\u6838\u5fc3\u5de5\u5177\u7c7b<\/h5>\n<ul>\n<li>Resources&#xff1a;\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6<\/li>\n<li>XMLConfigBuilder&#xff1a;\u89e3\u6790 XML \u914d\u7f6e<\/li>\n<li>DataSourceUtil&#xff1a;\u83b7\u53d6\u6570\u636e\u5e93\u8fde\u63a5<\/li>\n<li>Executor&#xff1a;\u6267\u884c SQL \u5e76\u5c01\u88c5\u7ed3\u679c<\/li>\n<\/ul>\n<h3>\u4e94\u3001\u539f\u59cb DAO \u5f00\u53d1&#xff08;\u4e86\u89e3&#xff09;<\/h3>\n<h4>5.1 DAO \u5b9e\u73b0\u7c7b<\/h4>\n<p>public class UserDaoImpl implements UserDao {<br \/>\n    private SqlSession sqlSession;<\/p>\n<p>    public UserDaoImpl(SqlSession sqlSession) {<br \/>\n        this.sqlSession &#061; sqlSession;<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public List&lt;User&gt; findAll() {<br \/>\n        return sqlSession.selectList(&#034;com.hg.dao.UserDao.findAll&#034;);<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public User findUserById(Integer id) {<br \/>\n        return sqlSession.selectOne(&#034;com.hg.dao.UserDao.findUserById&#034;, id);<br \/>\n    }<\/p>\n<p>    \/\/ \u5176\u4ed6CRUD\u65b9\u6cd5\u5b9e\u73b0&#8230;<br \/>\n}<\/p>\n<h4>5.2 \u539f\u59cb DAO vs \u4ee3\u7406 DAO \u5bf9\u6bd4<\/h4>\n<table>\n<tr>\u7279\u6027\u539f\u59cb DAO\u4ee3\u7406 DAO<\/tr>\n<tbody>\n<tr>\n<td>\u4ee3\u7801\u91cf<\/td>\n<td>\u9700\u624b\u52a8\u5b9e\u73b0 DAO \u7c7b<\/td>\n<td>\u4ec5\u9700\u63a5\u53e3 &#043; Mapper&#xff0c;\u81ea\u52a8\u751f\u6210\u4ee3\u7406<\/td>\n<\/tr>\n<tr>\n<td>\u7ef4\u62a4\u6210\u672c<\/td>\n<td>\u9ad8&#xff08;SQL \u4e0e\u4ee3\u7801\u8026\u5408&#xff09;<\/td>\n<td>\u4f4e&#xff08;SQL \u96c6\u4e2d\u914d\u7f6e&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u5f00\u53d1\u6548\u7387<\/td>\n<td>\u4f4e<\/td>\n<td>\u9ad8<\/td>\n<\/tr>\n<tr>\n<td>\u4e3b\u6d41\u7a0b\u5ea6<\/td>\n<td>\u51e0\u4e4e\u6dd8\u6c70<\/td>\n<td>\u76ee\u524d\u4e3b\u6d41<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<p>MyBatis \u4f5c\u4e3a\u8f7b\u91cf\u7ea7\u6301\u4e45\u5c42\u6846\u67b6&#xff0c;\u6838\u5fc3\u4f18\u52bf\u5728\u4e8e&#xff1a;<\/p>\n<li>\u7b80\u5316 JDBC \u64cd\u4f5c&#xff0c;\u4e13\u6ce8 SQL \u5f00\u53d1<\/li>\n<li>\u7075\u6d3b\u7684 SQL \u914d\u7f6e&#xff0c;\u652f\u6301\u52a8\u6001 SQL \/ \u5173\u8054\u67e5\u8be2<\/li>\n<li>\u4f4e\u4fb5\u5165\u6027&#xff0c;\u4e0e Spring \u7b49\u6846\u67b6\u65e0\u7f1d\u6574\u5408<\/li>\n<li>\u5f3a\u5927\u7684\u7ed3\u679c\u6620\u5c04&#xff0c;\u652f\u6301\u590d\u6742\u5bf9\u8c61\u5c01\u88c5<\/li>\n<p>\u638c\u63e1 MyBatis \u6838\u5fc3\u539f\u7406&#xff0c;\u4e0d\u4ec5\u80fd\u719f\u7ec3\u4f7f\u7528\u6846\u67b6&#xff0c;\u66f4\u80fd\u7406\u89e3\u5176\u8bbe\u8ba1\u601d\u60f3&#xff0c;\u4e3a\u89e3\u51b3\u590d\u6742\u4e1a\u52a1\u573a\u666f\u6253\u4e0b\u57fa\u7840\u3002<\/p>\n<hr \/>\n<p>\u5982\u679c\u672c\u6587\u5bf9\u4f60\u6709\u5e2e\u52a9&#xff0c;\u8bb0\u5f97\u6536\u85cf\u3001\u70b9\u8d5e\u3001\u5173\u6ce8~~~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001MyBatis \u6838\u5fc3\u4ecb\u7ecd1.1 \u4ec0\u4e48\u662f\u6846\u67b6\u6846\u67b6&#xff08;Framework&#xff09;\u662f\u8f6f\u4ef6\u5f00\u53d1\u7684 \\&#8221;\u534a\u6210\u54c1\\&#8221;&#xff0c;\u5b83\u5c01\u88c5\u4e86\u57fa\u7840\u4ee3\u7801\u5e76\u63d0\u4f9b\u6807\u51c6\u5316 API&#xff0c;\u5f00\u53d1\u8005\u57fa\u4e8e\u6846\u67b6\u5f00\u53d1\u53ef\u7701\u53bb\u91cd\u590d\u7f16\u7801\u5de5\u4f5c&#xff0c;\u5927\u5e45\u63d0\u5347\u5f00\u53d1\u6548\u7387\u3002\u5982\u679c\u628a\u6210\u54c1\u8f6f\u4ef6\u6bd4\u4f5c\u88c5\u4fee\u597d\u7684\u65b0\u623f&#xff0c;\u6846\u67b6\u5c31\u50cf\u6bdb\u576f\u623f \u2014\u2014 \u63d0\u4f9b\u57fa\u7840\u7ed3\u6784&#xff0c;\u4fdd\u8bc1\u6838\u5fc3\u8d28\u91cf&#xff0c;\u5f00\u53d1\u8005\u53ea\u9700\u4e13\u6ce8\u4e8e\u4e1a\u52a1\u903b\u8f91&#xff08;\u88c5\u4fee&#xff09;\u5373\u53ef\u30021.2 \u6846\u67b6\u8981\u89e3\u51b3\u7684\u6838\u5fc3\u95ee\u9898<\/p>\n","protected":false},"author":2,"featured_media":80278,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,1769,190],"topic":[],"class_list":["post-80279","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-mybatis","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>MyBatis \u4ece\u5165\u95e8\u5230\u7cbe\u901a - \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\/80279.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MyBatis \u4ece\u5165\u95e8\u5230\u7cbe\u901a - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u3001MyBatis \u6838\u5fc3\u4ecb\u7ecd1.1 \u4ec0\u4e48\u662f\u6846\u67b6\u6846\u67b6&#xff08;Framework&#xff09;\u662f\u8f6f\u4ef6\u5f00\u53d1\u7684 &quot;\u534a\u6210\u54c1&quot;&#xff0c;\u5b83\u5c01\u88c5\u4e86\u57fa\u7840\u4ee3\u7801\u5e76\u63d0\u4f9b\u6807\u51c6\u5316 API&#xff0c;\u5f00\u53d1\u8005\u57fa\u4e8e\u6846\u67b6\u5f00\u53d1\u53ef\u7701\u53bb\u91cd\u590d\u7f16\u7801\u5de5\u4f5c&#xff0c;\u5927\u5e45\u63d0\u5347\u5f00\u53d1\u6548\u7387\u3002\u5982\u679c\u628a\u6210\u54c1\u8f6f\u4ef6\u6bd4\u4f5c\u88c5\u4fee\u597d\u7684\u65b0\u623f&#xff0c;\u6846\u67b6\u5c31\u50cf\u6bdb\u576f\u623f \u2014\u2014 \u63d0\u4f9b\u57fa\u7840\u7ed3\u6784&#xff0c;\u4fdd\u8bc1\u6838\u5fc3\u8d28\u91cf&#xff0c;\u5f00\u53d1\u8005\u53ea\u9700\u4e13\u6ce8\u4e8e\u4e1a\u52a1\u903b\u8f91&#xff08;\u88c5\u4fee&#xff09;\u5373\u53ef\u30021.2 \u6846\u67b6\u8981\u89e3\u51b3\u7684\u6838\u5fc3\u95ee\u9898\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/80279.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-03-04T13:01:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260304130124-69a82d24e21c1.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=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/80279.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/80279.html\",\"name\":\"MyBatis \u4ece\u5165\u95e8\u5230\u7cbe\u901a - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-03-04T13:01:26+00:00\",\"dateModified\":\"2026-03-04T13:01:26+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/80279.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/80279.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/80279.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MyBatis \u4ece\u5165\u95e8\u5230\u7cbe\u901a\"}]},{\"@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 \u4ece\u5165\u95e8\u5230\u7cbe\u901a - \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\/80279.html","og_locale":"zh_CN","og_type":"article","og_title":"MyBatis \u4ece\u5165\u95e8\u5230\u7cbe\u901a - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u3001MyBatis \u6838\u5fc3\u4ecb\u7ecd1.1 \u4ec0\u4e48\u662f\u6846\u67b6\u6846\u67b6&#xff08;Framework&#xff09;\u662f\u8f6f\u4ef6\u5f00\u53d1\u7684 \"\u534a\u6210\u54c1\"&#xff0c;\u5b83\u5c01\u88c5\u4e86\u57fa\u7840\u4ee3\u7801\u5e76\u63d0\u4f9b\u6807\u51c6\u5316 API&#xff0c;\u5f00\u53d1\u8005\u57fa\u4e8e\u6846\u67b6\u5f00\u53d1\u53ef\u7701\u53bb\u91cd\u590d\u7f16\u7801\u5de5\u4f5c&#xff0c;\u5927\u5e45\u63d0\u5347\u5f00\u53d1\u6548\u7387\u3002\u5982\u679c\u628a\u6210\u54c1\u8f6f\u4ef6\u6bd4\u4f5c\u88c5\u4fee\u597d\u7684\u65b0\u623f&#xff0c;\u6846\u67b6\u5c31\u50cf\u6bdb\u576f\u623f \u2014\u2014 \u63d0\u4f9b\u57fa\u7840\u7ed3\u6784&#xff0c;\u4fdd\u8bc1\u6838\u5fc3\u8d28\u91cf&#xff0c;\u5f00\u53d1\u8005\u53ea\u9700\u4e13\u6ce8\u4e8e\u4e1a\u52a1\u903b\u8f91&#xff08;\u88c5\u4fee&#xff09;\u5373\u53ef\u30021.2 \u6846\u67b6\u8981\u89e3\u51b3\u7684\u6838\u5fc3\u95ee\u9898","og_url":"https:\/\/www.wsisp.com\/helps\/80279.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-03-04T13:01:26+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260304130124-69a82d24e21c1.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/80279.html","url":"https:\/\/www.wsisp.com\/helps\/80279.html","name":"MyBatis \u4ece\u5165\u95e8\u5230\u7cbe\u901a - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-03-04T13:01:26+00:00","dateModified":"2026-03-04T13:01:26+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/80279.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/80279.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/80279.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"MyBatis \u4ece\u5165\u95e8\u5230\u7cbe\u901a"}]},{"@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\/80279","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=80279"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/80279\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/80278"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=80279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=80279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=80279"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=80279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}