当前位置:网站首页>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刷题:二叉树23(二叉搜索树中的众数)
- Airserver automatically receives multi screen projection or cross device projection
- The road to success in R & D efficiency of 1000 person Internet companies
- Decrypt gd32 MCU product family, how to choose the development board?
- Realize all, race, allsettled and any of the simple version of promise by yourself
- SQL lab 11~20 summary (subsequent continuous update) contains the solution that Firefox can't catch local packages after 18 levels
- SQL head injection -- injection principle and essence
- How to use PS link layer and shortcut keys, and how to do PS layer link
- 2022-07-07日报:GAN发明者Ian Goodfellow正式加入DeepMind
- 利用栈来实现二进制转化为十进制
猜你喜欢
【统计学习方法】学习笔记——支持向量机(上)
[statistical learning method] learning notes - support vector machine (I)
SQL Lab (46~53) (continuous update later) order by injection
Aike AI frontier promotion (7.7)
Charles: four ways to modify the input parameters or return results of the interface
Day-15 common APIs and exception mechanisms
H3C HCl MPLS layer 2 dedicated line experiment
The IDM server response shows that you do not have permission to download the solution tutorial
leetcode刷题:二叉树21(验证二叉搜索树)
The road to success in R & D efficiency of 1000 person Internet companies
随机推荐
When OSPF specifies that the connection type is P2P, it enables devices on both ends that are not in the same subnet to Ping each other
Day-16 set
ps链接图层的使用方法和快捷键,ps图层链接怎么做的
ICLR 2022 | 基于对抗自注意力机制的预训练语言模型
图形对象的创建与赋值
编译 libssl 报错
爱可可AI前沿推介(7.7)
File upload vulnerability - upload labs (1~2)
The hoisting of the upper cylinder of the steel containment of the world's first reactor "linglong-1" reactor building was successful
解密GD32 MCU产品家族,开发板该怎么选?
Connect to blog method, overload, recursion
Object. Simple implementation of assign()
GCC compilation error
【统计学习方法】学习笔记——支持向量机(下)
Cryptography series: detailed explanation of online certificate status protocol OCSP
The road to success in R & D efficiency of 1000 person Internet companies
JS to convert array to tree data
2022危险化学品生产单位安全生产管理人员考题及在线模拟考试
Several ways to clear floating
SQL Lab (36~40) includes stack injection, MySQL_ real_ escape_ The difference between string and addslashes (continuous update after)