需求
使用springmvc和mybatis完成商品列表查询。
整合dao
mybatis和spring进行整合。
sqlMapConfig.xml
mybatis自己的配置文件。
applicationContext-dao.xml
逆向工程生成po类及mapper(单表增删改查)
手动定义商品查询mapper
针对综合查询mapper,一般情况会有关联查询,建议自定义mapper
ItemsMapperCustom.xml
ItemsQueryVo
ItemsCustom
ItemsMapperCustom.java
整合service
让spring管理service接口。
定义service接口
在spring容器配置service(applicationContext-service.xml)
创建applicationContext-service.xml,文件中配置service。
事务控制(applicationContext-transaction.xml)
整合springmvc
springmvc.xml
创建springmvc.xml文件,配置处理器映射器、适配器、视图解析器。
配置前端控制器
编写Controller(就是Handler)
编写jsp
加载spring容器
将mapper、service、controller加载到spring容器中。
建议使用通配符加载上边的配置文件。
在web.xml中,添加spring容器监听器,加载spring容器。