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映射文件中。

相关推荐
ss2732 小时前
ruoyi 新增每页分页条数
java·数据库·mybatis
x***44014 小时前
Spring-boot3.4最新版整合swagger和Mybatis-plus
mybatis
哈库纳玛塔塔14 小时前
放弃 MyBatis,拥抱新一代 Java 数据访问库
java·开发语言·数据库·mybatis·orm·dbvisitor
小马爱打代码1 天前
MyBatis:插件模块详解
mybatis
Codeking__1 天前
Redis初识——什么是Redis
数据库·redis·mybatis
y***n6141 天前
Spring Boot中集成MyBatis操作数据库详细教程
数据库·spring boot·mybatis
hqp1 天前
SQLite 不支持 LocalDateTime
sqlite·mybatis
用户8307196840821 天前
秒杀面试!MyBatis-Spring-Boot 初始化流程深度拆解
spring boot·mybatis
8***f3951 天前
Spring 中使用Mybatis,超详细
spring·tomcat·mybatis
w***76551 天前
Spring Boot 集成 MyBatis 全面讲解
spring boot·后端·mybatis