目录
1、当我们创建好一个Maven项目后,在pom.xml配置文件中导入Mybatis的相关依赖
-
- <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.0modelVersion>
-
- <groupId>org.examplegroupId>
- <artifactId>mybatis01artifactId>
- <version>1.0-SNAPSHOTversion>
- <packaging>warpackaging>
-
- <name>mybatis01 Maven Webappname>
-
- <url>http://www.example.comurl>
-
- <properties>
- <maven.compiler.source>1.8maven.compiler.source>
- <maven.compiler.target>1.8maven.compiler.target>
- properties>
-
- <dependencies>
-
- <dependency>
- <groupId>junitgroupId>
- <artifactId>junitartifactId>
- <version>4.12version>
- <scope>testscope>
- dependency>
-
-
- <dependency>
- <groupId>javax.servletgroupId>
- <artifactId>javax.servlet-apiartifactId>
- <version>4.0.0version>
- <scope>providedscope>
- dependency>
-
-
- <dependency>
- <groupId>org.mybatisgroupId>
- <artifactId>mybatisartifactId>
- <version>3.4.5version>
- dependency>
-
-
- <dependency>
- <groupId>mysqlgroupId>
- <artifactId>mysql-connector-javaartifactId>
- <version>5.1.44version>
- dependency>
-
-
-
-
-
- <dependency>
- <groupId>org.apache.logging.log4jgroupId>
- <artifactId>log4j-coreartifactId>
- <version>2.9.1version>
- dependency>
- <dependency>
- <groupId>org.apache.logging.log4jgroupId>
- <artifactId>log4j-apiartifactId>
- <version>2.9.1version>
- dependency>
-
- <dependency>
- <groupId>org.apache.logging.log4jgroupId>
- <artifactId>log4j-webartifactId>
- <version>2.9.1version>
- dependency>
- dependencies>
-
- <build>
- <finalName>mybatis01finalName>
-
-
- <resources>
-
- <resource>
- <directory>src/main/javadirectory>
- <includes>
- <include>**/*.xmlinclude>
- includes>
- resource>
-
- <resource>
- <directory>src/main/resourcesdirectory>
- <includes>
- <include>jdbc.propertiesinclude>
- <include>*.xmlinclude>
- includes>
- resource>
- resources>
- <pluginManagement>
- <plugins>
- <plugin>
- <artifactId>maven-clean-pluginartifactId>
- <version>3.1.0version>
- plugin>
-
- <plugin>
- <artifactId>maven-resources-pluginartifactId>
- <version>3.0.2version>
- plugin>
- <plugin>
- <artifactId>maven-compiler-pluginartifactId>
- <version>3.8.0version>
- plugin>
- <plugin>
- <artifactId>maven-surefire-pluginartifactId>
- <version>2.22.1version>
- plugin>
- <plugin>
- <artifactId>maven-war-pluginartifactId>
- <version>3.2.2version>
- plugin>
- <plugin>
- <artifactId>maven-install-pluginartifactId>
- <version>2.5.2version>
- plugin>
- <plugin>
- <artifactId>maven-deploy-pluginartifactId>
- <version>2.8.2version>
- plugin>
-
- <plugin>
- <groupId>org.mybatis.generatorgroupId>
- <artifactId>mybatis-generator-maven-pluginartifactId>
- <version>1.3.2version>
- <dependencies>
-
- <dependency>
- <groupId>mysqlgroupId>
- <artifactId>mysql-connector-javaartifactId>
- <version>5.1.44version>
- dependency>
- dependencies>
- <configuration>
- <overwrite>trueoverwrite>
- configuration>
- plugin>
-
- plugins>
- pluginManagement>
- build>
- project>
2、添加数据库连接的配置文件 jdbc.properties
- jdbc.driver=com.mysql.jdbc.Driver
- jdbc.url=jdbc:mysql://localhost:3306/zjy?useUnicode=true&characterEncoding=UTF-8
- jdbc.username=root
- jdbc.password=123456
3、导入mybatis的配置文件
- configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
- <configuration>
-
- <properties resource="jdbc.properties"/>
-
- <settings>
- <setting name="logImpl" value="LOG4J2"/>
- settings>
-
-
- <typeAliases>
-
- typeAliases>
-
-
-
- <environments default="development">
- <environment id="development">
-
- <transactionManager type="jdbc"/>
-
-
-
-
-
- <dataSource type="POOLED">
- <property name="driver"
- value="${jdbc.driver}"/>
- <property name="url"
- value="${jdbc.url}"/>
- <property name="username" value="${jdbc.username}"/>
- <property name="password" value="${jdbc.password}"/>
- dataSource>
- environment>
- environments>
-
- <mappers>
- <mapper resource="com/javaxl/mapper/BookMapper.xml"/>
- mappers>
- configuration>
在mybatis配置文件中引入数据库连接的配置文件

加载驱动

4、下载相关插件

其中maven helper插件能够将jar包之间的依赖关系呈树形结构展示,一目了然

在pom。xml文件中引入该插件的字符串下载到本地仓库中

注意:该插件不支持高版本的sql驱动
2、配置 generatorConfig.xml
2.1修改mysql的jar包存放路径,一定要与本地仓库位置相匹配

2.2修改实体类、dao层和sql对应配置文件的生成地址并且指定需要生成增删改查代码的表
3、配置Maven的mybatis逆向生成代码的commond line命令


然后就成功生成了t_oa_permission的增删改查代码
