Spring和Mybatis整合

Spring和Mybatis整合
1.相关jar包
Spring和Mybatis整合_第1张图片
Spring和Mybatis整合_第2张图片
Spring和Mybatis整合_第3张图片
Spring和Mybatis整合_第4张图片
Spring和Mybatis整合_第5张图片
2.Mybatis配置文件 这里可以设置一些全局属性
Mybatis提供了很多属性我这里列了写常用的,大家可以参考文档配置需要的属性。
Spring和Mybatis整合_第6张图片
3.Spring配置文件
主要是配置整合Mybatis
a.数据库配置我们采用properties文件,这样方便我们修改。
使用context 要在xml文件开头引用哦
b.数据库连接池 这里使用c3p0
Spring和Mybatis整合_第7张图片
c.配置SqlSessionFactory对象,Mybatis提供的对Spring的支持
Spring和Mybatis整合_第8张图片
这里的属性值一定要记得替换成自己的配置文件地址和实体包名哦
d.配置扫描Dao接口包
动态实现到接口,并注入到spring容器中
这里写图片描述
以上就是 Spring和Mybatis整合 的主要配置 当然还有Mybatis mapper的sql配置我这里就不说的大家可以参考Mybatis文档。

你可能感兴趣的:(java)