Spring+Spring MVC+myBatis整合(使用maven)
ssm整合报各种异常,看了众多帖子,都是零零散散,浪费时间,所以自己写了一篇,内含详细目录以及所有代码,无尿点爽文!
一.搭建环境
1.IDEA 2019
2.Maven
3.Spring+Spring MVC+myBatis
4.MySQL,表名为login(id,name,password)三个字段
5.目录结构图(使用的都是login部分)
二.导入Maven依赖
pom.xml部分
<?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>org.example</groupId>
<artifactId>ssmDay1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>ssmDay1 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>
<!-- spring 相关版本 -->
<spring.version>5.3.2</spring.version>
<!-- json 相关版本 -->
<json.version>2.9.0</json.version>
<!-- mybatis 相关版本 -->
<mybatis.version>3.5.5</mybatis.version>
<!-- mybatis 整合 spring 相关版本 -->
<mybatis-spring.version>2.0.6</mybatis-spring.version>
<!-- druid 相关版本 -->
<druid.version>1.2.4</druid.version>
<!-- c3p0 相关版本 -->
<c3p0.version>0.9.5.2</c3p0.version>
<!-- log4j 相关版本 -->
<log4j.version>2.14.0</log4j.version>
<!-- slf4j 相关版本 -->
<slf4j.version>1.7.30</slf4j.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- 导入 servlet 依赖 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<!-- 导入 jsp 依赖 -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
<!-- 导入 jstl 依赖 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- mysql连接驱动依赖 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<!-- 导入 spring 依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${
spring.version}</version>
</dependency>
<!-- 导入 springMVC 依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>