Maven+mybatis+mysql项目实践(附demo)
准备工作
- Maven搭建与工程建立(参考http://blog.csdn.net/kevinbetterq/article/details/77967856)
- mysql安装
接下来我们的项目在我上一篇Maven创建Web项目的基础上进行添加:
( 文章末尾附上实现的一个demo )
1、数据库建测试表
2、修改pom.xml文件
添加以下代码,加入依赖:
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
</dependencies>
完整pom.xml
<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.qwk</groupId>
<artifactId>spring_mybatis_1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependen