**最近使用mybatis-generator自动生成mapper和pojo文件时直接在网上找的GeneratorMapper.xml 文件 及相关 plugin,配置完成后遇到了
【 Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.6:generate (default-cli) on project 005-springboot-mybatis: configfile D:\IDEAProject\SpringBoot\005-springboot-mybatis\Classpath:GeneratorMapper.xml does not exist
】
下面是相关源码
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>
<!-- 指定连接数据库的JDBC驱动包所在位置,指定到你本机的完整路径 -->
<classPathEntry location="D:/repository/mysql/mysql-connector-java/5.1.43/mysql-connector-java-5.1.43.jar"/>
<!-- 配置table表信息内容体,targetRuntime指定采用MyBatis3的版本 -->
<context id="tables" targetRuntime="MyBatis3">
<!--序列化-->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
<!--以下需要插件 -->
<!--
插入成功后返回ID
<plugin type="cn.doity.common.generator.plugin.InsertAndReturnKeyPlugin"/>
分页查询功能
<plugin type="cn.doity.common.generator.plugin.SelectByPagePlugin"/>
生成带有for update后缀的select语句插件
<plugin type="cn.doity.common.generator.plugin.SelectForUpdatePlugin"/> -->
<!-- 抑制生成注释,由于生成的注释都是英文的,可以不让它生成 -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- 配置数据库连接信息 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.32.128:3306/music"
userId="root"
password="123456">
</jdbcConnection>
<!-- 生成model类,targetPackage指定model类的包名, targetProject指定生成的model放在eclipse的哪个工程下面-->
<javaModelGenerator targetPackage="com.zc.book.model" targetProject="book_server_ssm">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="false" />
</javaModelGenerator>
<!-- 生成MyBatis的Mapper.xml文件,targetPackage指定mapper.xml文件的包名, targetProject指定生成的mapper.xml放在eclipse的哪个工程下面 -->
<sqlMapGenerator targetPackage="com.zc.book.dao" targetProject="book_server_ssm">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- 生成MyBatis的Mapper接口类文件,targetPackage指定Mapper接口类的包名, targetProject指定生成的Mapper接口放在eclipse的哪个工程下面 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.zc.book.dao" targetProject="book_server_ssm">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- 数据库表名及对应的Java模型类名 -->
<table tableName="table2"
domainObjectName="table2"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"/>
</context>
</generatorConfiguration>
pom依赖设置为:
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.6</version>
<configuration>
<!--配置文件的位置 -->
<configurationFile>classpath:GeneratorMapper.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
数据库相关配置设置确认无误之后, 运行报错,检查之后发现是我将【GeneratorMapper.xml】文件放在了项目根目录之下
但在pom依赖中的
在【GeneratorMapper.xml】之前加了【classpath:】,取消掉这一行之后
如图所示,mapper和model成功自动建立
文中相关代码来源于
https://blog.youkuaiyun.com/myth_g/article/details/79471172
我只是在搬运过程中解决了一些小问题