Spring+SpringMVC+MyBatis整合应用

1)搭建Spring,SpringMVC和MyBatis环境
创建一个web工程
添加MyBatis相关环境
引入数据库驱动包和DBCP连接池开发包
引入MyBatis开发包
添加Spring,SpringMVC相关技术环境
引入Spring ioc,jdbc-tx,aop开发包
引入Spring web,webmvc开发包
在src下添加spring.xml配置文件
在web.xml中配置DispatcherServlet前端控制器和中文乱码
处理过滤器CharacterEncodingFilter
引入MyBatis和Spring整合开发包mybatis-spring.jar包

2)基于MapperScannerConfigurer方式整合MyBatis
根据数据表编写实体类
编写Mapper映射文件,在XML中添加SQL操作的定义
编写Mapper接口,定义SQL操作方法
在Spring配置文件中定义以下Bean组件
DataSource
SqlSessionFactoryBean
MapperScannerConfigurer

3)编写和配置SpringMVC的主要组件(Controller,HandlerMapper,ViewResolver)
编写Controller和请求处理方法
配置<mvc:annotation-drivern/> 主要支持@RequestMapping注解扫描
配置Controller组件
开启组件扫描,将Controller组件扫描到Spring容器中
需要DAO时,采用注入方式进行注入
在请求处理方法上使用@RequestMapping指定对应请求

4)编写JSP视图组件,利用JSTL标签和EL表达式显示数据
引入JSTL开发包(jstl.jar , standard.jar)

原文地址:https://www.cnblogs.com/yingyigongzi/p/9295330.html