目录
[二、mybatis 与 hibernate 的区别](about:blank#%E4%BA%8C%E3%80%81mybatis%E4%B8%8Ehibernate%E7%9A%84%E5%8C%BA%E5%88%AB)
一、Mybatis 的 Dao 编写【mapper 代理方式实现】
Mapper 代理的开发方式,程序员只需要编写 mapper 接口(相当于 dao 接口)即可。Mybatis 会自动的为 mapper 接口生成动态代理实现类。不过要实现 mapper 代理的开发方式****,需要遵循一些开发规范。****
<table border="1" cellpadding="1" cellspacing="1"><caption><span style="color:#f33b45;"><strong>开发规范</strong></span></caption><tbody><tr><td><p>1、mapper 接口的全限定名要和 mapper 映射文件的 namespace 的值相同。</p></td></tr><tr><td><p style="margin-left:0pt;">2、mapper 接口的方法名称要和 mapper 映射文件中的 statement 的 id 相同。</p></td></tr><tr><td>3、mapper 接口的方法参数只能有一个,且类型要和 mapper 映射文件中 statement 的 parameterType 的值保持一致。</td></tr><tr><td>4、mapper 接口的返回值类型要和 mapper 映射文件中 statement 的 resultType 值或 resultMap 中的 type 值保持一致</td></tr></tbody></table>
<table border="1" cellpadding="1" cellspacing="1"><caption><strong><span style="color:#f33b45;">编写步骤</span></strong></caption><tbody><tr><td><p><strong>第一步:重新写个 UserMapper 文件和定义 mapper 映射文件 UserMapper.xml(内容同 Users.xml,<span style="color:#ff0000;">除了 namespace 的值&