myBatis3之xml映射配置(mappers)

myBatis3之xml映射配置(mappers)

 

既然MyBatis的行为已经由上述元素配置完了,我们现在就要定义SQL映射语句了。但是,首先我们需要告诉MyBatis到哪里去找到这些语句。Java在这方面没有提供一个很好的方法,所以最佳的方式是告诉MyBatis到哪里去找映射文件。你可以使用相对于类路径的资源引用,或者字符表示,或url引用的完全限定名(包括file:///URLs)。例如:

<mappers> 
	<mapper resource="org/mybatis/builder/AuthorMapper.xml"/> 
	<mapper resource="org/mybatis/builder/BlogMapper.xml"/> 
	<mapper resource="org/mybatis/builder/PostMapper.xml"/> 
</mappers>
<mappers> 
	<mapper url="file:///var/sqlmaps/AuthorMapper.xml"/> 
	<mapper url="file:///var/sqlmaps/BlogMapper.xml"/> 
	<mapper url="file:///var/sqlmaps/PostMapper.xml"/> 
</mappers> 
  这些语句简单告诉了MyBatis去哪里找映射文件。

你可能感兴趣的:(Mybatis3)