美文网首页
mybatis-config.xml中获取Mapper映射文件的

mybatis-config.xml中获取Mapper映射文件的

作者: 问瑾遗 | 来源:发表于2019-04-06 22:04 被阅读0次

获取文件路径一般分两种:相对路径和绝对路径
相对路径法,mybatis-config.xml在src目录下,获取src文件夹下mapping包下UserinfoMapper.xml映射文件示例
第一种写法:直接获取SQL映射xml文件

<mapper resource="mapping/UserinfoMapper.xml"/>

第二种写法:扫描包,注意接口的名称和xml的文件的主文件名必须一致

<mapper resource="mapping"/>

第三种写法:指定接口名称,注意接口的名称和xml的文件的主文件名必须一致

<mapper resource="mapping.UserinfoMapper"/>

绝对路径法
第四种写法:

<mapper resource="file:\\\C:\Users\workspace\MyBatis01\src\mapping\UserinfoMapper.xml"/>

相关文章

网友评论

      本文标题:mybatis-config.xml中获取Mapper映射文件的

      本文链接:https://www.haomeiwen.com/subject/pppdiqtx.html