步骤

  1. 引入mybatis

    1.1 引入mybatis主配置文件:mybatis-config.xml

    1.2编写mapper接口,编写方法及注解

    1.3编写service()

    1.4编写service对象测试方法

  2. 引入spring

    2.1编写主配置文件:application-context.xml

    2.2在测试类中测试spring是否引用成功:编写一个bean,利用applicationContext.getBean(xxx.class)获取实例测试

  3. 开始整合mybatis-spring

    3.1 利用spring创建mybatis需要的dataSource。spring为mybatis提供一个类,可以专门用来连接数据库,spring-jdbc.dataSource:负责连接、管理数据库

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver"></property><property name="url" value="jdbc:mysql://localhost:3308/mybatis?useUnicode=true&amp;characterEncoding=UTF-8"></property><property name="username" value="root"></property><property name="password" value="123456"></property></bean>
    复制代码

    3.2 配置factory:

    mybatis为mybatis与spring整合时提供了一个工具类,用来创建factory,在mybatis-spring包中

    <bean id="factory" class="org.mybatis.spring.SqlSessionFactoryBean"><!-- 配置dataSource:连接到数据库 --><property name="dataSource" ref="dataSource"></property>
    </bean>
    复制代码

    3.3 开启扫描,作用类似于mybatis-config.xml mappers->package。mybatis-spring 为整合时提供了一个类, 可以用来扫描mybatis的mapper,这个类:可以帮程序员自动生成session及mapper对象,就不需要程序员手动的创建

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><!-- 指定扫描的包 --><property name="basePackage" value="com.dyr.mapper"></property><!-- 配置工厂 --><property name="sqlSessionFactory" ref="factory"></property>
    </bean>
    复制代码

3.4 配置service

     <bean id="studentService" class="com.dyr.service.StudentService"><!-- 第3步扫描自动生成StudentMapper --><property name="mapper" ref="studentMapper"></property></bean>
复制代码

3.5 事务配置:待续...

3.6引入action

<bean id="studentAction" class="com.dyr.action.StudentAction" scope="prototype"><property name="service" ref="studentService"></property></bean>
复制代码

3.7 在web.xml引入spring核心库

转载于:https://juejin.im/post/5c7de43f6fb9a049f362d688

mybatis-spring-struts2整合相关推荐

  1. MyBatis+Spring+Struts2

    MyBatis3.1.1+Spring3.1.2+Struts2.3.4.1 先来看目录结构 来看配置文件 applicationContext.xml <?xml version=" ...

  2. 总结MyBatis+Spring的整合

    第一步: 首先jar包导入.必要jar包,即缺失了就会不能正常启动,若需要用到额外功能,导入相关jar包即可 commons-logging-1.2.jarlog4j.jarspring-aop-4. ...

  3. Spring Boot 整合MyBatis(23)

    Spring Boot 整合MyBatis Spring Boot 整合 Druid 引入依赖 配置 application.yml pring Boot 整合 tk.mybatis 引入依赖 配置 ...

  4. 2021-5-10:Spring Boot整合MyBatis

    Spring Boot整合MyBatis Spring Boot 整合MyBatis (一)基础环境搭建 1.数据准备 创建数据库.数据表并插入一定的数据 (1)创建博客数据库blog 在Navica ...

  5. Spring+Struts2+Mybatis在Intellij下的整合

    环境:jdk 1.8,      tomcat 8.0.38; 开发工具:Intellj; 具体步骤: 1. 创建一个maven下的web项目 2. 配置相应的jar文件,具体的配置方式为: < ...

  6. SSM(spring.struts2.mybatis)注解式开发步骤

    SSM注解式开发步骤 1.引入依赖 spring.mybatis.struts2.mybatis-spring.struts2-spring-plugin.mysql|oracle.fastjson. ...

  7. Spring笔记 整合SSM[Struts2框架] 万神小栈

    一 spring概述 1.1 web项目开发中的耦合度问题 微信小程序搜索 万神小栈 更多资源等你发现! 如果文章对你有帮助别忘了点赞加关注喔~ 在servlet中需要调用service中的方法,则需 ...

  8. spring struts2 mybatis框架学习总结(mvc三层架构)

    spring struts2 mybatis框架学习总结(mvc三层架构) ssi的框架主要是由struts2,spring以及ibatis组成,他们负责各层之间的交互与协作,从而实现整个web端的功 ...

  9. MyBatis数据持久化(十一)Mybatis3、Spring4、Struts2整合开发

    上一节我们將Mybatis和Spring4进行整合,本节向大家介绍Mybatis在Web开发中的应用,并与主流的MVC框架Struts2进行整合. 我们首先需要获取Struts2框架,Struts2官 ...

  10. struts2+ibatis+spring框架整合(二)

    MyBatis3.1.1+Spring3.1.2+Struts2.3.4.1框架整合 先来看目录结构 来看配置文件 applicationContext.xml <?xml version=&q ...

最新文章

  1. 【BZOJ】1692: [Usaco2007 Dec]队列变换
  2. IT职场新人第一课:我的吐槽+我学到的
  3. rpm | 升级软件包
  4. FLASH得到MYSQL数据
  5. Python稳基修炼之计算机等级考试易错概念题5(含答案)
  6. MVC自学系列之四(MVC模型-Models)
  7. Android 系统自带的图标
  8. 热烈祝贺排名进入前1000
  9. Python制作黑客工具,发现了同学U盘里见不得人的秘密
  10. Java修改图片分辨率(附代码) | Java工具类
  11. 三款新品重磅齐发!汉高亮相2021中国国际纺织面料及辅料(秋冬)博览会
  12. while循环因为内部使用ssh命令而导致不能循环文件的所有行
  13. 加快MATLAB运行速度的三个方法
  14. SEO优化是什么意思,如何理解并学好它
  15. 阿里云创建及管理bucket(二)
  16. it 决策者用户_了解最终用户的安全决策
  17. IFE_js_task03
  18. 区块链存证原理与流程--基于xuperchain司法存证系统开发的学习笔记
  19. Revit 2016 笔记07
  20. 苹果H5免签封装iosAPP完善版修复图标-绿标 亲测一切正常 带分发

热门文章

  1. 中山大学计算机学院官网万海,中山大学
  2. 8月7日晚八点分享-推荐系统面试/概览
  3. 242.有效的字母异位词
  4. MySQL常用命令介绍
  5. 画五角星中间没有填充_冷军画两个白色五角星,卖出230万,专家大呼:这不是画...
  6. 分类战车SVM (第四话:拉格朗日对偶问题)
  7. 协方差矩阵、相关矩阵的详细说明
  8. 特征选择和共线性问题
  9. 【Gym - 101848D】XOR【多个数异或的典型问题】【费马小定理】
  10. chrome.storage和window.localStorage的区别