映射器(mappers)
MapperRegistry:注册绑定我们的Mapper文件;
方式一:
<!-- 每一个Mapper.xml都需要在Mybatis核心配置文件中注册,记得这里是 / 来表示路径-->
<mappers>
<mapper resource="com/xie/dao/UserMapper.xml"></mapper>
</mappers>
扫描包:
<!-- 每一个Mapper.xml都需要在Mybatis核心配置文件中注册,记得这里是 / 来表示路径-->
<mappers>
<mapper resource="com/xie/dao/*.xml"></mapper>
</mappers>
方式二:
<mappers>
<mapper class="com.xie.dao.UserMapper"></mapper>
</mappers>
注意点:
- 接口(UserMapper.java)和它的Mapper配置(UserMapper.xml)文件必须同名!
- 接口(UserMapper.java)和它的Mapper配置文件(UserMapper.xml)必须在同一个包下!
方式三:
使用扫描包进行注入绑定
<mappers>
<package name="com.xie.dao"/>
</mappers>
注意点:
- 接口(UserMapper.java)和它的Mapper配置(UserMapper.xml)文件必须同名!
- 接口(UserMapper.java)和它的Mapper配置文件(UserMapper.xml)必须在同一个包下!
最好用方式一,而且最好接口(UserMapper.java)和它的Mapper配置文件(UserMapper.xml)放在同一个包下