记录学习的点滴(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属性,不能都指定,也不能都不指定。
<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属性,不能都指定,也不能都不指定。
相关文章推荐
- MyBatis学习记录(3):Mapper动态代理方式开发DAO
- 记录学习的点滴(MyBatis log4j日志输出配置)
- 记录学习的点滴(Spring+MyBatis注解配置)
- Mybatis3.2.1使用例三:Mapper方式集成Spring、配置文件提供SQL
- 使用mybatis执行对应的SQL Mapper配置中的insert、update、delete等标签操作,数据库记录不变
- MyBatis学习笔记-Spring集成DAO层实现方式记录
- 记录学习的点滴(MyBatis缓存机制学习)
- mybatis的4种Mapper注册方式
- mybatis学习笔记--mapper配置文件中大于小于怎么处理
- Spring-Security (学习记录四)--配置权限过滤器,采用数据库方式获取权限
- MyBatis学习记录(4):MyBatis配置文件的优化
- MyBatis MapperScannerConfigurer配置——MyBatis学习笔记之一
- Mybatis学习记录(二)--Mybatis开发DAO方式
- MyBatis mapper.xml配置一对多的两种方式
- 记录学习的点滴(Eclipse+Spring+Mybatis搭建问题总结)
- Unity学习笔记1-以配置文件方式注册组件
- Mybatis学习笔记-CURD(基于配置文件的方式)
- Mybatis学习笔记-CURD(基于配置文件的方式)
- (五)mybatis学习之mapper代理开发方式及与spring整合
- 记录学习的点滴(Struts2的Action配置)