博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
整合SSM
阅读量:4347 次
发布时间:2019-06-07

本文共 2264 字,大约阅读时间需要 7 分钟。

SSM整合:

Spring - SpringMVC -  MyBatis
1.
Spring -  MyBatis   :    需要整合:将MyBatis的SqlSessionFactory 交给Spring
2
Spring - SpringMVC  :  就是将Spring - SpringMVC 各自配置一遍

思路:

可以发现 ,MyBatis最终是通过SqlSessionFactory来操作数据库,
Spring整合MyBatis 其实就是 将MyBatis的SqlSessionFactory 交给Spring

1.jar

2.类-表

3.-(与Spring整合时,conf.xml可省)--MyBatis配置文件conf.xml(数据源、mapper.xml) --可省,将该文件中的配置 全部交由spring管理

spring配置文件 applicationContext.xml
4.通过mapper.xml将 类、表建立映射关系
5.
之前使用MyBatis:    conf.xml ->SqlSessionFacotry
现在整合的时候,需要通过Spring管理SqlSessionFacotry ,因此 产生qlSessionFacotry 所需要的数据库信息 不在放入conf.xml  而需要放入spring配置文件中

 

配置Spring配置文件(applicationContext.xml)  (Web项目):

web.xml    
contextConfigLocation
classpath:applicationContext.xml    //当有多个xml配置文件               classpath:spring_dao.xml               classpath:spring_service.xml     
org.springframework.web.context.ContextLoaderListener

6.使用Spring整合MyBatis :将MyBatis的SqlSessionFactory 交给Spring

spring-dao.xml 
classpath:db.properties

 

7.继续整合SpringMVC:将springmvc加入项目即可

a.加入SpringMVC需要的jar
spring-webmvc.jar
b.给项目加入SpringMVC支持
web.xml: dispatcherServlet
c.编写springmvc配置文件:
applicationContext-controller.xml:视图解析器、基础配置

web.xml
springDispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:applicationContext-controller.xml
1
springDispatcherServlet
/

 

spring-mvc.xml

 

转载于:https://www.cnblogs.com/wskb/p/11512647.html

你可能感兴趣的文章
java并发:join源码分析
查看>>
算法设计--查找无序数组中第K大的数字
查看>>
项目中使用WCF替换asmx Web service总结
查看>>
CriminalIntent项目开发笔记(四)----使用fragment argument
查看>>
hdu 1055 Color a Tree(树上贪心,4级)
查看>>
nodejs 之 fs模块
查看>>
转:Fuzzing Apache httpd server with American Fuzzy Lop + persistent mode
查看>>
史上最简短的文章长内容的代码,转
查看>>
网络流二十四题 分配问题
查看>>
NetWaiting 完美卸载方法
查看>>
必做作业2:视频剪辑软件调研
查看>>
[学习笔记]Javascript的包装对象
查看>>
第三次作业 个人统计分析报告
查看>>
ajax传参里含有特殊字符的坑
查看>>
python3.5 字典遍历
查看>>
proxy跨域
查看>>
走出迷宫
查看>>
月饼_5
查看>>
镜像二叉树
查看>>
2. LNMP安装了哪些软件
查看>>