tedwhy 发表于 2016-11-25 06:43:13

MyBatis-Spring MVC 整合示例(带源码)

      Mybatis怎么整合Spring?       由于目前Spring官方还没有出整合Mybatis的特性,所以这里在Spring框架和MyBatis框架上再添加用于整合的框架“mybatis-spring-1.0.2.jar” (该框架时MyBatis官方自己出的)。 
      虽然我熟悉ibatis但迫于时代的压力,我毅然选择了mybatis。在MyBatis的基础上不能否定ibatis,所以mybatis只晨ibatis上进行了升级和修改。
 
Mybaits为什么要整合Spring?
说白了其实就想使用Spring提供的服务,比如Spring的事务管理、Spring的IOC对Bean进行管理等。
开发依赖库:
JavaEE5、Spring 3.0.5、Mybatis 3.0.4、myBatis-spring-1.0、junit4.8.1
   
企业级项目实战(带源码)地址:  http://zz563143188.iyunv.com/blog/1825168

收集五年的开发资料下载地址:  http://pan.baidu.com/share/home?uk=4076915866&view=share

  项目源码请下载codeFactory20130321,lib20130321LI两个文件,
  github查看项目源码地址      https://github.com/zl19861124/codeFactory  
请下载codeFactory20130320,lib20130320文件,工程src目录下面有数据库脚本及操作说明

 
     如果觉得我的例子太深(本人主要针对新手,把很多细节的知识点描述出来了,建议先看我的再给友人的),可以参考简单例子 http://duzitianya.iyunv.com/blog/814884
一、准备工作:
  1、下载jar包(我已都下载好放到项目中去了)
Spring3 jar下载:
http://ebr.springsource.com/repository/app/library/version/detail?name=org.springframework.spring&version=3.0.5.RELEASE
MyBatis3 jar 下载:
http://www.mybatis.org/java.html
junit 4 jar下载:
http://www.junit.org/

 

2、创建mybatis的配置文件 

3.配置user.xml文件也就与数据库打交道的POJO文件

4.创建spring的配置文件

4、JavaBean(Model、Entity,POJO)相关类、


5、创建dao接口mybatis 的mapper对象
 
6、创建service和action层就不用实现了,很简单的可参考 http://zz563143188.iyunv.com/blog/1825168 
 
7.调用测试类,查看打印结果

Ok,至此spring 和mybatis就整合好了。

三、用junit进行单元测试





 
页: [1]
查看完整版本: MyBatis-Spring MVC 整合示例(带源码)