1、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>com.cn</groupId> <artifactId>MyBatis_HelloWorld</artifactId> <version>1.0-SNAPSHOT</version> <!-- 设置打包方式 --> <packaging>jar</packaging> <dependencies> <!-- MyBatis依赖 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.7</version> </dependency> <!-- JUnit依赖 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <!-- MySQL依赖 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.37</version> </dependency> <!-- log4j依赖 --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.2.0</version> </dependency> </dependencies> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> </properties> </project>
resources下的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="db.properties"></properties> <settings> <!--开启驼峰命名自动映射--> <setting name="mapUnderscoreToCamelCase" value="true"/> <!--开启延迟加载--> <setting name="lazyLoadingEnabled" value="true"/> <!--关闭积极加载--> <setting name="aggressiveLazyLoading" value="false"/> <!--开启二级缓存的全局配置--> <setting name="cacheEnabled" value="true"/> </settings> <typeAliases><!-- 给返回值类型起别名 默认是类名--> <!-- <typeAlias type="com.cn.pojo.User" ></typeAlias>--> <!--直接指定一个包,默认是类名--> <package name="com.cn.pojo"/> </typeAliases> <!-- 配置数据源 --> <environments default="development"> <environment id="development"> <transactionManager type="JDBC"/> <dataSource type="POOLED"> <!-- 配置数据库驱动 --> <property name="driver" value="${db.driver}"/> <!-- 配置数据库地址 --> <property name="url" value="${db.url}"/> <!-- 连接数据库所需的用户名 --> <property name="username" value="${db.username}"/> <!-- 连接数据库所需的密码 --> <property name="password" value="${db.password}"/> </dataSource> </environment> </environments> <!-- 设置mapper的路径 --> <mappers> <!-- 注意是//--> <package name="com.cn.mapper"/> </mappers> <plugins> <plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin> </plugins> </configuration>
标签:xml,配置文件,mybatis,mysql,MyBatis,junit From: https://www.cnblogs.com/shangeg/p/17742510.html