1.1 需求和步骤分析
需求
使用ssm框架完成对 account 表的增删改查操作。
步骤分析
1. 准备数据库和表记录
2. 创建web项目
3. 编写mybatis在ssm环境中可以单独使用
4. 编写spring在ssm环境中可以单独使用
5. spring整合mybatis
6. 编写springMVC在ssm环境中可以单独使用
7. spring整合springMVC
1.2 环境搭建
1)准备数据库和表记录
2)创建web项目
1.3 编写mybatis在ssm环境中可以单独使用
需求:基于mybatis先来实现对account表的查询
1)相关坐标
2)Account实体
3)AccountDao接口
4)AccountDao.xml映射
5)mybatis核心配置文件
jdbc.properties
SqlMapConfig.xml
6)测试代码
1.4 编写spring在ssm环境中可以单独使用
1)相关坐标
2)AccountService接口
3)AccountServiceImpl实现
4)spring核心配置文件
applicationContext.xml
5)测试代码
1.5 spring整合mybatis
1)整合思想
将mybatis接口代理对象的创建权交给spring管理,我们就可以把dao的代理对象注入到service中,
此时也就完成了spring与mybatis的整合了。
2)导入整合包
3)spring配置文件管理mybatis
注意:此时可以将mybatis主配置文件删除。
4)修改AccountServiceImpl
1.6 编写springMVC在ssm环境中可以单独使用
需求:访问到controller里面的方法查询所有账户,并跳转到list.jsp页面进行列表展示
1)相关坐标
2)导入页面资源
3)前端控制器DispathcerServlet
4)AccountController和 list.jsp
5)springMVC核心配置文件
1.7 spring整合springMVC
1)整合思想
spring和springMVC其实根本就不用整合,本来就是一家。
但是我们需要做到spring和web容器整合,让web容器启动的时候自动加载spring配置文件,web容
器销毁的时候spring的ioc容器也销毁。
2)spring和web容器整合
ContextLoaderListener加载【掌握】
可以使用spring-web包中的ContextLoaderListener监听器,可以监听servletContext容器的创建和
销毁,来同时创建或销毁IOC容器。
3)修改AccountController
1.8 spring配置声明式事务
1)spring配置文件加入声明式事务
2)add.jsp
3)AccountController
4)AccountService接口和实现类
5)AccountDao
void save(Account account);
6)AccountDao.xml映射
1.9 修改操作
1.9.1 数据回显
① AccountController
② AccountService接口和实现类
③ AccountDao接口和映射文件
④ update.jsp
1.9.2 账户更新
① AccountController
② AccountService接口和实现类
③ AccountDao接口和映射文件
1.10 批量删除
1)list.jsp
2)AccountController
3)AccountService接口和实现类
void deleteBatch(Integer[] ids);