MyBatis
- MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis 。2013年11月迁移到Github。
- iBATIS一词来源于“internet”和“abatis”的组合,是一个基于Java的持久层框架。iBATIS提供的持久层框架包括SQL Maps和Data Access Objects(DAO)
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.jege.mybatis</groupId>
<artifactId>mybatis-single-table</artifactId>
<version>1.0.0.RELEASE</version>
<packaging>jar</packaging>
<name>mybatis-single-table</name>
<url>http://blog.csdn.net/je_ge</url>
<developers>
<developer>
<id>je_ge</id>
<name>je_ge</name>
<email>1272434821@qq.com</email>
<url>http://blog.csdn.net/je_ge</url>
<timezone>8</timezone>
</developer>
</developers>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mybatis.version>3.4.1</mybatis.version>
<mysql.version>5.1.40</mysql.version>
<junit.version>4.12</junit.version>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<!-- 过滤掉所有依赖的jar文件不使用 -->
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>mybatis-single-table</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
jdbc.properties
jdbc.url=jdbc:mysql:///mybatis?createDatabaseIfNotExist=true
jdbc.driver=com.mysql.jdbc.Driver
jdbc.username=root
jdbc.password=admin
log4j.properties
log4j.rootCategory=ERROR, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
log4j.logger.com.jege.mybatis=TRACE
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="jdbc.properties"></properties>
<!-- 类型别别名 -->
<typeAliases>
<typeAlias type="com.jege.mybatis.mapper.User" alias="User" />
</typeAliases>
<!-- mybatis数据库连接和应用环境 -->
<environments default="dev">
<environment id="dev">
<!-- JDBC事务 -->
<transactionManager type="JDBC" />
<!-- 配置数据库的属性) -->
<dataSource type="POOLED">
<property name="url" value="${jdbc.url}" />
<property name="driver" value="${jdbc.driver}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</dataSource>
</environment>
</environments>
<!-- 加载mybatis的映射文件 -->
<mappers>
<mapper resource="com/jege/mybatis/mapper/UserMapper.xml" />
</mappers>
</configuration>
源码地址
https://github.com/je-ge/mybatis
如果觉得我的文章或者代码对您有帮助,可以请我喝杯咖啡。您的支持将鼓励我继续创作!谢谢!