generatorConfig.xml代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!-- targetRuntime:用来设置生成的方式:是简单版(MyBatis3Simple)还是豪华版(MyBatis3) -->
<context id="DB2Tables" targetRuntime="MyBatis3Simple">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是;false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/student" userId="root"
password="root">
</jdbcConnection>
<!-- 选配 -->
<!-- <javaTypeResolver> -->
<!-- <property name="forceBigDecimals" value="false" /> -->
<!-- </javaTypeResolver> -->
<!-- 配置POJO的生成策略 targetPackage:实体类的全路径 targetProject:在哪个数据源下 -->
<javaModelGenerator targetPackage="com.hwb.entities"
targetProject=".\src\main\java">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- sql映射文件的生成策略 targetPackage:放置MyBatis文件的全路径 targetProject:在哪个数据源下 -->
<sqlMapGenerator targetPackage="com.hwb.mapper"
targetProject=".\src\main\resources">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- mapper接口的生成策略 targetPackage:实体类对应的接口的全路径 targetProject:在哪个数据源下 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.hwb.mapper" targetProject=".\src\main\java">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 设置逆向分析的表的表名以及对应的POJO实体类 指定数据库中的哪个表自动创建,并且指定该表对应的实体类名 tableName:表明
domainObjectName:对应的实体类 -->
<table tableName="student" domainObjectName="Student"></table>
</context>
</generatorConfiguration>
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.atguigu</groupId>
<artifactId>mbg</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 导入mybatis核心包依赖 -->
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- 配置MBG插件 -->
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.0</version>
<dependencies>
<!-- MBG工具的核心包 -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
<!-- 数据库连接池 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.2</version>
</dependency>
<!-- 数据库驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.8</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
执行命令mybatis-generation:generate
报错:
[INFO] Scanning for projects...
[INFO] Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
[INFO] Downloading: http://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
[INFO] Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml (14 KB at 13.3 KB/sec)
[INFO] Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml (20 KB at 2.6 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.711 s
[INFO] Finished at: 2019-06-25T22:46:50+08:00
[INFO] Final Memory: 9M/164M
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'mybatis-generation' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (D:\maven\maven), central (http://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException