SpringMvc与Mybatis整合
1.目的
学习SpringMvc与Mybatis怎样整合在一起。
2.环境准备
1) jdk版本:jdk1.7或jdk1.8
2) IDE:eclipse
3) Tomcat:Apache Tomcat v7.0
4) 数据库:mysql及navicat for mysql
3.整合
3.1.新建一个web项目
注意:这里选择Dynamic Web Module 2.5 ,因为2.5是主流,默认在eclipse的WebContent \WEB-INF\目录下创建web.xml的,而3.0则默认没有web.xml文件
3.2.添加整合所需的jar包
注:所有的包已经放到文件jar里面了
3.3.web.xml配置
3.3.1.代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
http://www.springmodules.org/schema/cache/springmodules-cache.xsd
http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>SpringMvc-Mybatis</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- Spring配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 编码过滤器 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 添加对springmvc的支持 -->
<