当前位置:网站首页>SSM框架搭建的步骤
SSM框架搭建的步骤
2022-07-07 10:37:00 【泗水六年】
SSM框架搭建的步骤
1. 导入Spring、SpringMVC、MyBatis的依赖
2. 导入Spring、SpringMVC、MyBatis的配置文件
3. 在Spring的配置文件中配置如下内容:
(1)配置数据源
(2)配置MyBatis的会话工厂SqlSessionFactoryBean,并注入数据源
(3)配置MyBatis自动扫描DAO层Mapper接口和配置MyBatis映射文件的路径
(4)通过component-scan注解开启对service层的扫描
(5)配置事务的传播特性、隔离级别、回滚策略,让那些以add、delete、update开头的方法开启事务的提交和回滚,其它方法走的是只读事务。
(6)配置事务管理切面类,横切service层。
4. 在SpringMVC配置文件中配置如下内容:
(1)使用component-scan标签开启对controller层的扫描
(2)通过annotation-driven标签开启注解驱动
(3)配置视图解析器
(4)如果需要进行文件上传操作,还需要配置文件上传解析器,并指定文件上传的大小 限制
5. 在MyBatis的配置文件中配置如下内容:
(1)配置在控制台打印SQL语句
(2)配置开启二级缓存
(3)配置下划线自动转小驼峰
6. 在web.xml中配置如下内容
(1)配置Spring的监听,并加载Spring的配置文件
(2)配置SpringMVC的核心控制器DispatcherServlet并加载SpringMVC的配置文件
(3)为了防止中文乱码,一般还会配置一个编码过滤器并设置字符编码集为UTF-8
7. 其实到此为止,咱们的SSM框架就算搭建完毕了,接下来就可以进行项目的开发了。
新建控制层并在类上加上@Controller注解,然后在控制层类的方法上添加@RequestMapping注解,接下来在控制层类中通过@Autowired或@Resource注解注入Service层,在Service层通过@Autowired或@Resource注解注入DAO层,这里需要注意的是,DAO层只有接口没有实现类,是通过MyBatis映射文件中的namespace指明实现的DAO层Mapper接口,并通过MyBatis映射文件中的SQL的ID指明调用DAO层Mapper接口方法时要执行的SQL语句。
边栏推荐
- leetcode刷题:二叉树20(二叉搜索树中的搜索)
- 2022危险化学品生产单位安全生产管理人员考题及在线模拟考试
- Niuke website
- On valuation model (II): PE index II - PE band
- ICLR 2022 | 基于对抗自注意力机制的预训练语言模型
- visual stdio 2017关于opencv4.1的环境配置
- Tutorial on principles and applications of database system (007) -- related concepts of database
- About IPSec
- 【从 0 开始学微服务】【01】什么是微服务
- 【PyTorch实战】用PyTorch实现基于神经网络的图像风格迁移
猜你喜欢

对话PPIO联合创始人王闻宇:整合边缘算力资源,开拓更多音视频服务场景

NPM instal reports agent or network problems

Dialogue with Wang Wenyu, co-founder of ppio: integrate edge computing resources and explore more audio and video service scenarios

【统计学习方法】学习笔记——支持向量机(上)

Attack and defense world - PWN learning notes

SQL Lab (32~35) contains the principle understanding and precautions of wide byte injection (continuously updated later)

ICLR 2022 | 基于对抗自注意力机制的预训练语言模型

SQL Lab (36~40) includes stack injection, MySQL_ real_ escape_ The difference between string and addslashes (continuous update after)

浅谈估值模型 (二): PE指标II——PE Band

Financial data acquisition (III) when a crawler encounters a web page that needs to scroll with the mouse wheel to refresh the data (nanny level tutorial)
随机推荐
Niuke website
2022-07-07日报:GAN发明者Ian Goodfellow正式加入DeepMind
[statistical learning method] learning notes - support vector machine (Part 2)
About IPSec
Zhimei creative website exercise
The left-hand side of an assignment expression may not be an optional property access. ts(2779)
聊聊Redis缓存4种集群方案、及优缺点对比
Cookie
OSPF exercise Report
[statistical learning methods] learning notes - improvement methods
SQL Lab (32~35) contains the principle understanding and precautions of wide byte injection (continuously updated later)
Epp+dis learning path (1) -- Hello world!
SQL Lab (41~45) (continuous update later)
Static comprehensive experiment
Visual stdio 2017 about the environment configuration of opencv4.1
ACL 2022 | 序列标注的小样本NER:融合标签语义的双塔BERT模型
2022危险化学品生产单位安全生产管理人员考题及在线模拟考试
Multi row and multi column flex layout
Object. Simple implementation of assign()
[statistical learning methods] learning notes - Chapter 5: Decision Tree