当前位置:网站首页>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刷题:二叉树24(二叉树的最近公共祖先)
- 解决 Server returns invalid timezone. Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually
- How much does it cost to develop a small program mall?
- 【从 0 开始学微服务】【01】什么是微服务
- Guangzhou held work safety conference
- Object. Simple implementation of assign()
- Day-14 common APIs
- The left-hand side of an assignment expression may not be an optional property access.ts(2779)
- Tutorial on principles and applications of database system (007) -- related concepts of database
- Common knowledge of one-dimensional array and two-dimensional array
猜你喜欢

数据库安全的重要性
![[pytorch practice] image description -- let neural network read pictures and tell stories](/img/39/b2c61ae0668507f50426b01f2deee4.png)
[pytorch practice] image description -- let neural network read pictures and tell stories

2022广东省安全员A证第三批(主要负责人)考试练习题及模拟考试

【PyTorch实战】图像描述——让神经网络看图讲故事

【统计学习方法】学习笔记——提升方法

IPv6 experiment

About web content security policy directive some test cases specified through meta elements

Session

How to use PS link layer and shortcut keys, and how to do PS layer link

Dialogue with Wang Wenyu, co-founder of ppio: integrate edge computing resources and explore more audio and video service scenarios
随机推荐
Epp+dis learning path (1) -- Hello world!
基于NeRF的三维内容生成
爱可可AI前沿推介(7.7)
聊聊Redis缓存4种集群方案、及优缺点对比
【从 0 开始学微服务】【03】初探微服务架构
[statistical learning methods] learning notes - Chapter 4: naive Bayesian method
什么是ESP/MSR 分区,如何建立ESP/MSR 分区
Tutorial on the principle and application of database system (008) -- exercises on database related concepts
Day-16 set
The left-hand side of an assignment expression may not be an optional property access. ts(2779)
leetcode刷题:二叉树25(二叉搜索树的最近公共祖先)
密码学系列之:在线证书状态协议OCSP详解
Guangzhou held work safety conference
Preorder, inorder and postorder traversal of binary tree
Error in compiling libssl
Sort out the garbage collection of JVM, and don't involve high-quality things such as performance tuning for the time being
SQL Lab (41~45) (continuous update later)
静态Vxlan 配置
GCC compilation error
Polymorphism, final, etc