mybatis 映射器
mybatis 提供4种方式的映射器,如下图
<!-- 使用相对于类路径的资源引用 -->
<mappers>
<mapper resource="org/mybatis/builder/AuthorMapper.xml"/>
<mapper resource="org/mybatis/builder/BlogMapper.xml"/>
<mapper resource="org/mybatis/builder/PostMapper.xml"/>
</mappers>
<!-- 使用完全限定资源定位符(URL) -->
<mappers>
<mapper url="file:///var/mappers/AuthorMapper.xml"/>
<mapper url="file:///var/mappers/BlogMapper.xml"/>
<mapper url="file:///var/mappers/PostMapper.xml"/>
</mappers>
<!-- 使用映射器接口实现类的完全限定类名 -->
<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>
说是4种,其实就是2种,一个就是通过解析xml,生成MapperStatement,然后通过xml的namespace属性找到mapper接口,生成mapper接口的代理类,(然后通过mapper接口找同目录下的mapper.xml生成MapperStatement,由于xml在前面解析过,这里不能再次解析)再解析mapper接口方法上的注解,生成MapperStatement。
一种就是解析mapper接口,生成mapper接口的代理类,然后通过mapper接口找同目录下的mapper.xml生成MapperStatement,再解析mapper接口方法上的注解,生成MapperStatement。
还没有评论,来说两句吧...