您的位置:首页 > 移动开发

记录学习的点滴(Mybatis配置注册Mapper的方式)

2016-10-19 16:43 585 查看
mybatis-config.xml

<mappers>
<!-- 通过mapper元素的resource属性可以指定相对于类路径的Mapper.xml文件 -->
<mapper url="file:///E:/TestUserDao.xml"/>
<!-- 通过mapper元素的resource属性可以指定相对于类路径的Mapper.xml文件 -->
<!-- <mapper resource="com/springmybatis/system/dao/TestUserDao.xml" /> -->
<!-- 通过mapper元素的class属性可以指定Mapper接口进行注册 -->
<mapper class="com.springmybatis.system.dao.UserDao" />
<!-- 通过package元素将会把指定包下面的所有Mapper接口进行注册 -->
<package name="com.springmybatis.system.dao.transaction" />
</mappers>
当使用mapper元素进行Mapper定义的时候需要注意:mapper的三个属性resource、url和class对于每个mapper元素只能指定一个,要么指定resource属性,要么指定url属性,要么指定class属性,不能都指定,也不能都不指定。


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: