当前位置:网站首页>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语句。
边栏推荐
- ACL 2022 | 序列标注的小样本NER:融合标签语义的双塔BERT模型
- SQL lab 21~25 summary (subsequent continuous update) (including secondary injection explanation)
- Customize the web service configuration file
- NPM instal reports agent or network problems
- Day-20 file operation, recursive copy, serialization
- 解决 Server returns invalid timezone. Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually
- Idea 2021 Chinese garbled code
- Session
- 基于NeRF的三维内容生成
- About sqli lab less-15 using or instead of and parsing
猜你喜欢
BGP third experiment report
How to use PS link layer and shortcut keys, and how to do PS layer link
SQL head injection -- injection principle and essence
Epp+dis learning road (2) -- blink! twinkle!
leetcode刷题:二叉树20(二叉搜索树中的搜索)
Sorting, dichotomy
[爬虫]使用selenium时,躲避脚本检测
About IPSec
Customize the web service configuration file
The left-hand side of an assignment expression may not be an optional property access.ts(2779)
随机推荐
SQL lab 11~20 summary (subsequent continuous update) contains the solution that Firefox can't catch local packages after 18 levels
[Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘
图形对象的创建与赋值
Configure an encrypted web server
Inverted index of ES underlying principle
Is it safe to open an account in Ping An Securities mobile bank?
IPv6 experiment
Common knowledge of one-dimensional array and two-dimensional array
Will the filing free server affect the ranking and weight of the website?
Epp+dis learning road (2) -- blink! twinkle!
数据库安全的重要性
Zhimei creative website exercise
File upload vulnerability - upload labs (1~2)
【统计学习方法】学习笔记——第四章:朴素贝叶斯法
leetcode刷题:二叉树27(删除二叉搜索树中的节点)
【从 0 开始学微服务】【00】课程概述
Learning and using vscode
Static routing assignment of network reachable and telent connections
HZOJ #235. 递归实现指数型枚举
用mysql查询某字段是否有索引