官方文档:http://www.mybatis.org/mybatis-3/zh/configuration.html#mappers
(copy官方文档,当做笔记使用)
MyBatis支持查找映射文件的4种方式:
可以使用相对于类路径的资源引用、完全限定资源定位符(包括 file:/// 的 URL)、类名、包名等。这些配置会告诉MyBatis去哪里找映射文件,例如:
1. 使用相对于类路径的资源引用
<mappers>
<mapper resource="org/mybatis/mapper/AuthorMapper.xml"/>
<mapper resource="org/mybatis/mapper/BlogMapper.xml"/>
<mapper resource="org/mybatis/mapper/PostMapper.xml"/>
</mappers>
2. 使用完全限定资源定位符(URL)
<mappers>
<mapper url="file:///var/mappers/AuthorMapper.xml"/>
<mapper url="file:///var/mappers/BlogMapper.xml"/>
<mapper url="file:///var/mappers/PostMapper.xml"/>
</mappers>
3. 使用映射器接口实现类的完全限定类名
<mappers>
<mapper class="org.mybatis.mapper.AuthorMapper"/>
<mapper class="org.mybatis.mapper.BlogMapper"/>
<mapper class="org.mybatis.mapper.PostMapper"/>
</mappers>
4. 将包内的映射器接口实现全部注册为映射器
<mappers>
<package name="org.mybatis.mapper"/>
</mappers>