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> con.study</ groupId>
< artifactId> ssm-study-day01-1</ artifactId>
< version> 1.0-SNAPSHOT</ version>
< dependencies>
< dependency>
< groupId> junit</ groupId>
< artifactId> junit</ artifactId>
< version> 4.12</ version>
< scope> test</ scope>
</ dependency>
< dependency>
< groupId> mysql</ groupId>
< artifactId> mysql-connector-java</ artifactId>
< version> 5.1.47</ version>
</ dependency>
< dependency>
< groupId> org.mybatis</ groupId>
< artifactId> mybatis</ artifactId>
< version> 3.5.2</ version>
</ dependency>
< dependency>
< groupId> org.mybatis</ groupId>
< artifactId> mybatis-spring</ artifactId>
< version> 2.0.2</ version>
</ dependency>
< dependency>
< groupId> com.mchange</ groupId>
< artifactId> c3p0</ artifactId>
< version> 0.9.5.2</ version>
</ dependency>
< dependency>
< groupId> javax.servlet</ groupId>
< artifactId> javax.servlet-api</ artifactId>
< version> 2.5</ version>
</ dependency>
< dependency>
< groupId> javax.servlet.jsp</ groupId>
< artifactId> jsp-api</ artifactId>
< version> 2.2</ version>
</ dependency>
< dependency>
< groupId> javax.servlet</ groupId>
< artifactId> jstl</ artifactId>
< version> 1.2</ version>
</ dependency>
< dependency>
< groupId> org.springframework</ groupId>
< artifactId> spring-webmvc</ artifactId>
< version> 5.1.9.RELEASE</ version>
</ dependency>
< dependency>
< groupId> org.springframework</ groupId>
< artifactId> spring-jdbc</ artifactId>
< version> 5.1.9.RELEASE</ version>
</ dependency>
</ dependencies>
< build>
< resources>
< resource>
< directory> src/main/resources</ directory>
< includes>
< include> **/*.xml</ include>
< include> **/*.properties</ include>
</ includes>
< filtering> true</ filtering>
</ resource>
< resource>
< directory> src/main/java</ directory>
< includes>
< include> **/*.xml</ include>
< include> **/*.properties</ include>
</ includes>
< filtering> true</ filtering>
</ resource>
</ resources>
</ build>
</ project>
mybatis核心配置文件:mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
< configuration>
< properties resource = " " > </ properties>
< typeAliases>
< package name = " " />
</ typeAliases>
< environments default = " development" >
< environment id = " development" >
< transactionManager type = " JDBC" > </ transactionManager>
< dataSource type = " POOLED" >
< property name = " driver" value = " ${database.driver}" />
< property name = " url" value = " ${database.url}" />
< property name = " username" value = " ${database.username}" />
< property name = " password" value = " ${database.password}" />
</ dataSource>
</ environment>
</ environments>
< mappers>
< mapper resource = " " > </ mapper>
</ mappers>
</ configuration>
数据库配置文件:database.properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306
jdbc.username=
jdbc.password=
mybatis映射文件:mapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
< mapper namespace = " " >
< select id = " " resultType = " " >
select * from mybatis.user
</ select>
< insert id = " " parameterType = " " >
insert into mybatis.user (id,name,pwd) values (#{id},#{name},#{pwd});
</ insert>
< delete id = " " parameterType = " " >
delete from mybatis.user where id=#{id};
</ delete>
< update id = " " parameterType = " " >
update mybatis.user set name=#{name},pwd=#{pwd} where id=#{id};
</ update>
</ 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" >
< import resource = " spring-dao.xml" />
< import resource = " spring-service.xml" />
< import resource = " spring-mvc.xml" />
</ beans>