使用mybatis插件自动生成代码以及问题处理
1.pom.xml
中加入依赖插件
<!-- mybatis generator 自动生成代码插件 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
</plugin>
2. 在项目${basedir}/src/main/resources/generator/
目录下新建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>
<!-- 数据库驱动:选择本地硬盘上面的数据库驱动包-->
<classPathEntry location="E:\mvn\repository\mysql\5.1.2\lib\mysql-connector-java-5.1.25.jar"/>
<context id="DB2Tables" targetRuntime="MyBatis">
<commentGenerator>
<property name="suppressDate" value="true"/>
<!-- 是否去除自动生成的注释 true:是;false:否 -->
<property name="suppressAllComments" value="false"/>
</commentGenerator>
<!--数据库链接URL,用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1/orcl" userId="root" password="root">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- 生成模型的包名和位置-->
<javaModelGenerator targetPackage="main.java.com.coderzz.model" targetProject="src">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- 生成映射文件的包名和位置-->
<sqlMapGenerator targetPackage="main.resources.com.coderzz.mapping" targetProject="src">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 生成DAO的包名和位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="main.java.com.coderzz.mapper" targetProject="src">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
<table tableName="person" domainObjectName="Person" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
</context>
</generatorConfiguration>
3. 点击Run
->Edit Configurations
4. 新建Maven配置
5. 运行
结果提示以下错误,根据错误来看,提示No plugin found for prefix 'mybatis-generator' in the current project
,说明插件不存在,检查本地maven仓库发现,该插件已正常存在,寻找其它解决方法。
C:\java\jdk1.8.0_112\bin\java -Dmaven.multiModuleProjectDirectory=E:\Projects\war-fx-mock--bak "-Dmaven.home=D:\Program Files\apache-maven-3.3.9" "-Dclassworlds.conf=D:\Program Files\apache-maven-3.3.9\bin\m2.conf" -Didea.launcher.port=7536 "-Didea.launcher.bin.path=D:\Program Files\IntelliJIDEA\bin" -Dfile.encoding=UTF-8 -classpath "D:\Program Files\apache-maven-3.3.9\boot\plexus-classworlds-2.5.2.jar;D:\Program Files\IntelliJIDEA\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=2016.2.5 -s "D:\Program Files\apache-maven-3.3.9\conf\settings-nexus3_5_2.xml" -Dmaven.repo.local=E:\mvn\repository mybatis-generator:generate -e
[INFO] Error stacktraces are turned on.
[WARNING]
[WARNING] Some problems were encountered while building the effective settings
[WARNING] Unrecognised tag: 'pluginRepositories' (position: START_TAG seen ...</servers> \n\n <pluginRepositories>... @33:26) @ D:\Program Files\apache-maven-3.3.9\conf\settings-nexus3_5_2.xml, line 33, column 26
[WARNING]
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.mobanker.mock:mock-service:war:1.0.0-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework.boot:spring-boot-starter-web:jar -> duplicate declaration of version (?) @ com.mobanker.mock:mock-service:[unknown-version], E:\Projects\war-fx-mock--bak\mock-service\pom.xml, line 81, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] fx-mock
[INFO] mock-common
[INFO] mock-core
[INFO] mock-service
Downloading: http://test.nexus.ql.corp/repository/public/org/codehaus/mojo/maven-metadata.xml
Downloading: http://test.nexus.ql.corp/repository/public/org/apache/maven/plugins/maven-metadata.xml
Downloaded: http://test.nexus.ql.corp/repository/public/org/codehaus/mojo/maven-metadata.xml (22 KB at 80.7 KB/sec)
Downloaded: http://test.nexus.ql.corp/repository/public/org/apache/maven/plugins/maven-metadata.xml (14 KB at 49.4 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] fx-mock ............................................ SKIPPED
[INFO] mock-common ........................................ SKIPPED
[INFO] mock-core .......................................... SKIPPED
[INFO] mock-service ....................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.617 s
[INFO] Finished at: 2018-02-08T16:21:02+08:00
[INFO] Final Memory: 23M/230M
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'mybatis-generator' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (E:\mvn\repository), central (http://test.nexus.ql.corp/repository/public/)] -> [Help 1]
org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException: No plugin found for prefix 'mybatis-generator' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (E:\mvn\repository), central (http://test.nexus.ql.corp/repository/public/)]
at org.apache.maven.plugin.prefix.internal.DefaultPluginPrefixResolver.resolve(DefaultPluginPrefixResolver.java:93)
at org.apache.maven.lifecycle.internal.MojoDescriptorCreator.findPluginForPrefix(MojoDescriptorCreator.java:265)
at org.apache.maven.lifecycle.internal.MojoDescriptorCreator.getMojoDescriptor(MojoDescriptorCreator.java:219)
at org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator.calculateTaskSegments(DefaultLifecycleTaskSegmentCalculator.java:103)
at org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator.calculateTaskSegments(DefaultLifecycleTaskSegmentCalculator.java:83)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:89)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
[ERROR]
[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 Process finished with exit code 1
Error Info
6. 点击Maven Projects
->Plugins
,发现已经存在mybatis-generator
插件,右键点击该插件,选择运行Run Maven Build
,执行成功,代码自动生成:
C:\java\jdk1.8.0_112\bin\java -Dmaven.multiModuleProjectDirectory=E:\Projects\war-fx-mock\mock-service "-Dmaven.home=D:\Program Files\apache-maven-3.3.9" "-Dclassworlds.conf=D:\Program Files\apache-maven-3.3.9\bin\m2.conf" -Didea.launcher.port=7537 "-Didea.launcher.bin.path=D:\Program Files\IntelliJIDEA\bin" -Dfile.encoding=UTF-8 -classpath "D:\Program Files\apache-maven-3.3.9\boot\plexus-classworlds-2.5.2.jar;D:\Program Files\IntelliJIDEA\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=2016.2.5 -s "D:\Program Files\apache-maven-3.3.9\conf\settings-nexus3_5_2.xml" -Dmaven.repo.local=E:\mvn\repository org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate
[WARNING]
[WARNING] Some problems were encountered while building the effective settings
[WARNING] Unrecognised tag: 'pluginRepositories' (position: START_TAG seen ...</servers> \n\n <pluginRepositories>... @33:26) @ D:\Program Files\apache-maven-3.3.9\conf\settings-nexus3_5_2.xml, line 33, column 26
[WARNING]
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.mobanker.mock:mock-service:war:1.0.0-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework.boot:spring-boot-starter-web:jar -> duplicate declaration of version (?) @ com.mobanker.mock:mock-service:[unknown-version], E:\Projects\war-fx-mock\mock-service\pom.xml, line 81, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mock-service 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- mybatis-generator-maven-plugin:1.3.2:generate (default-cli) @ mock-service ---
[INFO] Connecting to the Database
Thu Feb 08 16:21:50 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
log4j:WARN No appenders could be found for logger (org.mybatis.generator.internal.db.DatabaseIntrospector).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[INFO] Introspecting table person
[INFO] Generating Record class for table person
[INFO] Generating Mapper Interface for table person
[INFO] Generating SQL Map for table person
[INFO] Saving file PersonMapper.xml
[INFO] Saving file Person.java
[INFO] Saving file PersonMapper.java
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.973 s
[INFO] Finished at: 2018-02-08T16:21:51+08:00
[INFO] Final Memory: 17M/171M
[INFO] ------------------------------------------------------------------------ Process finished with exit code 0
使用mybatis插件自动生成代码以及问题处理的更多相关文章
- IDEA结合mybatis插件自动生成代码
pom文件 添加插件 <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>myb ...
- 关于使用mybatis插件自动生成代码
1.安装 mybatis 插件: 在 eclipse 中 点击 help-->Install New Software...--> Add --> local 选择插件中eclip ...
- SpringBoot 添加mybatis generator 自动生成代码插件
自动生成数据层代码,提高开发效率 1.pom添加插件,并指定配置文件路径 <!-- mybatis generator 自动生成代码插件 --> <plugin> <gr ...
- SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件
原文链接 我们这一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池 ...
- Eclipse 使用mybatis generator插件自动生成代码
Eclipse 使用mybatis generator插件自动生成代码 标签: mybatis 2016-12-07 15:10 5247人阅读 评论(0) 收藏 举报 .embody{ paddin ...
- IDEA Maven Mybatis generator 自动生成代码
IDEA Maven Mybatis generator 自动生成代码 一.安装配置maven以及在Idea中配置maven 安装过程步骤可以看上面的博文,里面介绍得很详细. 二.建数据表 DROP ...
- IDEA Maven Mybatis generator 自动生成代码(实例讲解)(转)
IDEA Maven Mybatis generator 自动生成代码(实例讲解) MyBatis Generator • 简称MBG,是一个专门为MyBatis框架使用者定制的代码生成器,可以快速的 ...
- MyBatis框架之mybatis逆向工程自动生成代码
http://www.jb51.net/article/82062.htm Mybatis属于半自动ORM,在使用这个框架中,工作量最大的就是书写Mapping的映射文件,由于手动书写很容易出错,我们 ...
- idea中mybatis generator自动生成代码配置 数据库是sqlserver
好长时间没有写博客了,最近公司要用java语言,开始学习java,属于初学者,今天主要记录一下mybatis generator自动生成代码,首先在如下图的目录中新建两个文件,如下图 generato ...
随机推荐
- 谷歌protocolbuff使用说明步骤
Protocolbuff 目录 1 Protocolbuff定义和作用... 1 2 Protocolbuff的使用步骤... 1 3 .proto编写格式... ...
- 转自网络用LIBSVM进行回归预测的粗浅认识————————作者师梦
说一说我对用LIBSVM进行回归预测的粗浅认识(整理完成于2012年5.11) 作者 : 师梦 吾本工程小硕一枚,前用matlab建模,已然完成.某日,正沾沾自喜之际,吾师曰:“汝已为之 ...
- JS编程规范
在第一家公司用C++时,公司有着严格的代码规范,甚至到了严苛的地步,现在回想起来,对它充满感激.一个好的习惯让你收益终身. 之后使用JS/TS却没有为自己定一套编程规范,所幸为时不晚,在这里参考air ...
- tensorflow dnn 参考
https://blog.csdn.net/qq_35976351/article/details/80793487
- 使用EasyPrint实现不预览直接打印功能_非JS打印
插件地址 github 下载插件,安装后将在注册表中添加EasyPrint的协议 随后可以在开始->运行中输入EasyPrint://1&test 进行测试 参数分为两部分使用[&am ...
- C#连接内存数据库redis【1、Redis存读取数据】
这一节演示下载.NET中怎样使用Redis存储数据.在.net中比较常用的客户端类库是ServiceStack,看下通过servicestack怎样存储数据. DLL下载:https://github ...
- spring整合mybatis(代理的方式)【我】
创建项目等同上一篇非代理方式随笔,只说不一样的部分: 项目结构主要是多了下面红框部分: 配置文件: 主要是dao配置文件中多了Mapper代理java类的扫描包路径: applicationConte ...
- 七十四:flask信号之flask的内置信号
flask所有的内置信号 1.template_rendered:模板渲染完成后的信号2.before_render_template:模板渲染之前的信号3.request_started:模板开始渲 ...
- linux常用命令(16)locate命令
locate 让使用者可以很快速的搜寻档案系统内是否有指定的档案.其方法是先建立一个包括系统内所有档案名称及路径的数据库,之后当寻找时就只需查询这个数据库,而不必实际深入档案系统之中了.在一般的 di ...
- Eclipse 4.11 Debug jar包代码时进入空心J
代码调试时,进入jar包中的时候,会出现如下的情况超级影响代码调试 断点打在上面的地方,但是却进入到了空心J的那个地方了. 解决办法:去掉勾选即可. 我是这么解决的.