springmvc(五)springmvc和mybatis整合

来源:互联网 发布:七天网络阅卷公司 编辑:程序博客网 时间:2024/06/05 18:54

需求

使用springmvcmybatis完成商品列表查询。

整合dao

mybatisspring进行整合。

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容器

mapperservicecontroller加载到spring容器中。

建议使用通配符加载上边的配置文件。

web.xml中,添加spring容器监听器,加载spring容器。





0 0
原创粉丝点击