SSM整合思路与配置详解
SSM(Spring+SpringMvc+Mybatis)整合与配置
在网上扒拉了好久各种SSM整合后,觉得每次做项目都去网上扒配置特别麻烦,所以做了如下总结。
一、配置准备
在进行配置前,先想清楚要配置哪些文件,如图,除web.xml外,其余三个配置文件名称均可自定义。

如图所示,一共有四个需要手动配置的文件:
- web.xml:配置servlet、filter、listener
- applicationContext.xml:配置相关的bean,与mybatis整合
- SpringMvc.xml:用于配置视图解析器、控制器等
- Mybatis.xml:用于生成Mybatis用到的实体类、Mapper接口、Map配置文件 (由于要与spring进行整合,所以在真正配置的时候有些会合并到spring配置文件中配置)
二、配置过程
配置之前要在pom.xml中添加一定的依赖包。
下面是我做的时候进行的一些简单的依赖配置。
1.引入依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.may</groupId>
<artifactId>ssm_crud</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>ssm_crud Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<junit.version>4.12</junit.version>
<jstl.version>1.2</jstl.version>
<spring.version>4.3.7.RELEASE</spring.version>
<pagehelper.version>5.1.11</pagehelper.version>
<servlet-api.version>3.1.0</servlet-api.version>
<mybatis.version>3.4.2</mybatis.version>
<mybatis.spring.version>1.3.1</mybatis.spring.version>
<mybatis.generator.version>1.3.5</mybatis.generator.version>
<c3p0.version>0.9.1.2</c3p0.version>
<mysql.version>5.1.41</mysql.version>
</properties>
<!-- 引入jar包 -->
<!-- springmvc spring mybatis -->
<dependencies>
<!-- 分页 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
