[MyBatis]映射器

方式一(推荐)

<!-- 使用相对于类路径的资源引用 -->
<mappers>
  <mapper resource="org/mybatis/builder/AuthorMapper.xml"/>
  <mapper resource="org/mybatis/builder/BlogMapper.xml"/>
  <mapper resource="org/mybatis/builder/PostMapper.xml"/>
</mappers>

方式二:通过class绑定文件注册

<!-- 使用映射器接口实现类的完全限定类名 -->
<mappers>
  <mapper class="org.mybatis.builder.AuthorMapper"/>
  <mapper class="org.mybatis.builder.BlogMapper"/>
  <mapper class="org.mybatis.builder.PostMapper"/>
</mappers>

方式三:使用扫描包进行绑定

<!-- 将包内的映射器接口实现全部注册为映射器 -->
<mappers>
  <package name="org.mybatis.builder"/>
</mappers>

方式二和方式三:

注意点:

  •   接口和Mapper配置文件必须同名
  •   接口和Mapper配置文件必须在同一包内
posted @ 2021-03-11 11:44  雾霾王者  阅读(46)  评论(0编辑  收藏  举报