当前位置:网站首页>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语句。
边栏推荐
- BGP actual network configuration
- test
- Common knowledge of one-dimensional array and two-dimensional array
- [statistical learning method] learning notes - support vector machine (I)
- SQL Lab (41~45) (continuous update later)
- ps链接图层的使用方法和快捷键,ps图层链接怎么做的
- Decrypt gd32 MCU product family, how to choose the development board?
- SQL lab 26~31 summary (subsequent continuous update) (including parameter pollution explanation)
- Simple implementation of call, bind and apply
- 【统计学习方法】学习笔记——支持向量机(下)
猜你喜欢
Day-15 common APIs and exception mechanisms
Airserver automatically receives multi screen projection or cross device projection
【统计学习方法】学习笔记——第五章:决策树
Cookie
爱可可AI前沿推介(7.7)
OSPF exercise Report
Pule frog small 5D movie equipment | 5D movie dynamic movie experience hall | VR scenic area cinema equipment
Several ways to clear floating
IPv6 experiment
What if does not match your user account appears when submitting the code?
随机推荐
SQL blind injection (WEB penetration)
Day-20 file operation, recursive copy, serialization
通讯协议设计与实现
leetcode刷题:二叉树25(二叉搜索树的最近公共祖先)
Cryptography series: detailed explanation of online certificate status protocol OCSP
idm服务器响应显示您没有权限下载解决教程
Cookie
利用棧來實現二進制轉化為十進制
Charles: four ways to modify the input parameters or return results of the interface
数据库安全的重要性
leetcode刷题:二叉树26(二叉搜索树中的插入操作)
Processing strategy of message queue message loss and repeated message sending
2022广东省安全员A证第三批(主要负责人)考试练习题及模拟考试
【统计学习方法】学习笔记——第五章:决策树
金融数据获取(三)当爬虫遇上要鼠标滚轮滚动才会刷新数据的网页(保姆级教程)
GCC compilation error
OSPF exercise Report
[statistical learning methods] learning notes - Chapter 4: naive Bayesian method
mysql怎么创建,删除,查看索引?
Several ways to clear floating