第一种方式:mapper标签,通过resource属性引入classpath路径的相对资源

<mappers>
  <mapper resource="org/mybatis/builder/AuthorMapper.xml"/>
  <mapper resource="org/mybatis/builder/BlogMapper.xml"/>
  <mapper resource="org/mybatis/builder/PostMapper.xml"/>
</mappers>

第二种方式:mapper标签,通过url引入网络资源或者本地磁盘资源

<mappers>
  <mapper url="file:///var/mappers/AuthorMapper.xml"/>
  <mapper url="file:///var/mappers/BlogMapper.xml"/>
  <mapper url="file:///var/mappers/PostMapper.xml"/>
</mappers>

第三种方式:mapper标签,通过class属性指定mapper接口名称,此时对应的映射文件必须与接口位于同一路径下,并且名称相同
如mapper接口采用注解的方式,则无需映射文件

<mappers>
  <mapper class="org.mybatis.builder.AuthorMapper"/>
  <mapper class="org.mybatis.builder.BlogMapper"/>
  <mapper class="org.mybatis.builder.PostMapper"/>
</mappers>

第四种方式:package标签,通过name属性指定mapper接口所在的包名 ,此时对应的映射文件必须与接口位于同一路径下,并且名称相同
如mapper接口采用注解的方式,则无需映射文件

<mappers>
  <package name="org.mybatis.builder"/>
</mappers>

相关文章:

  • 2021-05-02
  • 2022-02-14
  • 2020-06-29
  • 2021-09-23
  • 2022-12-23
  • 2021-12-22
  • 2022-03-06
  • 2021-04-15
猜你喜欢
  • 2022-01-20
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2021-10-25
  • 2021-12-01
相关资源
相似解决方案