Mybatis配置-映射器(mappers)

现在,我们已经配置了MyBatis的行为,准备定义我们的映射SQL语句。但首先,我们需要告诉MyBatis在哪里找到它们。在这方面,Java并没有提供很好的自动发现机制,所以最好的方法是直接告诉MyBatis在哪里找到映射文件。 您可以使用类路径相对资源引用、完全限定的URL引用(包括file:///URL)、类名或包名。例如:

XML 复制代码
<!-- Using classpath relative resources -->
<mappers>
  <mapper resource="org/mybatis/builder/AuthorMapper.xml"/>
  <mapper resource="org/mybatis/builder/BlogMapper.xml"/>
  <mapper resource="org/mybatis/builder/PostMapper.xml"/>
</mappers>
XML 复制代码
<!-- Using url fully qualified paths -->
<mappers>
  <mapper url="file:///var/mappers/AuthorMapper.xml"/>
  <mapper url="file:///var/mappers/BlogMapper.xml"/>
  <mapper url="file:///var/mappers/PostMapper.xml"/>
</mappers>
XML 复制代码
<!-- Using mapper interface classes -->
<mappers>
  <mapper class="org.mybatis.builder.AuthorMapper"/>
  <mapper class="org.mybatis.builder.BlogMapper"/>
  <mapper class="org.mybatis.builder.PostMapper"/>
</mappers>
XML 复制代码
<!-- Register all interfaces in a package as mappers -->
<mappers>
  <package name="org.mybatis.builder"/>
</mappers>

这些配置语句只是告诉MyBatis接下来该去哪里,其余的细节都在每个SQL映射文件中。

相关推荐
han_hanker1 天前
mybatis-plus service层拥有的方法
mybatis
ruleslol2 天前
Mybatis11-不同的数据库连接池的配置
数据库·mybatis
干到60岁退休的码农2 天前
整合Mybatis-Plus分页插件并实现分页api方法
java·mybatis
han_hanker2 天前
mybatis-plus 常用方法
java·tomcat·mybatis
李少兄2 天前
MyBatis、MyBatis-Plus 与全自动 ORM 的本质区别
mybatis
干到60岁退休的码农2 天前
SpringBoot整合Mybatis-plus
spring boot·后端·mybatis
4154112 天前
MyBatis-Plus + PostGIS 实战(二):空间查询与空间索引
java·mybatis·gis·postgis
AgCl232 天前
JavaWeb个人笔记01--Maven到MyBatis
笔记·maven·mybatis
倒流时光三十年3 天前
MyBatis @MapKey 注解详解
windows·mybatis
从此以后自律5 天前
MyBatis-Plus 内置分页、PageHelper 自定义分页
mybatis