实现要求:

在Eclipse中搭建MyBatis基本开发环境。

如何在Eclipse中搭建MyBatis基本开发环境?(使用Eclipse创建Maven项目)_spring

实现步骤:

1、使用Eclipse创建Maven项目。File >> New >> Maven Project

如何在Eclipse中搭建MyBatis基本开发环境?(使用Eclipse创建Maven项目)_spring_02

如果这里没有的话就选择 Other >> Maven Poject

如何在Eclipse中搭建MyBatis基本开发环境?(使用Eclipse创建Maven项目)_eclipse_03 

如何在Eclipse中搭建MyBatis基本开发环境?(使用Eclipse创建Maven项目)_maven_04

2、打开Maven项目的配置文件pom.xml,配置源代码编码方式为UTF-8,设置编译源代码的JDK版本为1.6或更高。

如何在Eclipse中搭建MyBatis基本开发环境?(使用Eclipse创建Maven项目)_spring_05

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

如何在Eclipse中搭建MyBatis基本开发环境?(使用Eclipse创建Maven项目)_maven_06

<build>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-pluging</artifactId>
				<version>2.5.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
		</plugins>
	</build>

3、在pom.xml文件中分别添加MyBatis、JUnit、log4j、slf4j和MySQL的依赖坐标,上述依赖坐标可https://mvnrepository.com进行查找。

<dependencies>
		<!-- mybatis的依赖 -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>3.5.1</version>
		</dependency>
		<!-- junit的依赖 -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.10</version>
		</dependency>
		<!-- slf4j-log4j12的依赖 -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.7.26</version>
		</dependency>
		<!-- mysql的驱动依赖 -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.47</version>
		</dependency>
	</dependencies>

4、在项目上单击鼠标右键,在【Maven】中选择【Update Project...】来更新外部依赖的jar包。

如何在Eclipse中搭建MyBatis基本开发环境?(使用Eclipse创建Maven项目)_mybatis_07