相关依赖:
1 <dependencies> 2 <dependency> 3 <groupId>junit</groupId> 4 <artifactId>junit</artifactId> 5 <version>4.12</version> 6 </dependency> 7 <dependency> 8 <groupId>mysql</groupId> 9 <artifactId>mysql-connector-java</artifactId> 10 <version>5.1.47</version> 11 </dependency> 12 <dependency> 13 <groupId>org.mybatis</groupId> 14 <artifactId>mybatis</artifactId> 15 <version>3.5.2</version> 16 </dependency> 17 <dependency> 18 <groupId>org.mybatis</groupId> 19 <artifactId>mybatis-spring</artifactId> 20 <version>2.0.6</version> 21 </dependency> 22 <dependency> 23 <groupId>org.springframework</groupId> 24 <artifactId>spring-webmvc</artifactId> 25 <version>5.0.2.RELEASE</version> 26 </dependency> 27 <dependency> 28 <groupId>org.springframework</groupId> 29 <artifactId>spring-jdbc</artifactId> 30 <version>5.0.2.RELEASE</version> 31 </dependency> 32 <!-- https://mvnrepository.com/artifact/com.mchange/c3p0 --> 33 <dependency> 34 <groupId>com.mchange</groupId> 35 <artifactId>c3p0</artifactId> 36 <version>0.9.5.5</version> 37 </dependency> 38 </dependencies>
第一个配置文件:Mybatis核心配置文件————> mybatis-config.xml
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE configuration 3 PUBLIC "-//mybatis.org//DTD Config 3.0//EN" 4 "http://mybatis.org/dtd/mybatis-3-config.dtd"> 5 <!-- configuration核心配置文件 --> 6 <configuration> 7 </configuration>
第二个配置文件:Mybatis中的Mapper配置文件————> XXXMapper.xml
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE mapper 3 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 4 "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 5 <!-- Mapper配置文件 --> 6 <mapper namespace=""> 7 </mapper>
第三个配置文件:Spring核心配置文件————> applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
第四个配置文件:SpringMVC核心配置文件同Spring核心配置文件一致
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">