springboot+maven在eclipse上的逆向生成

springboot+maven在eclipse上的逆向生成

generator.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="D:\java\Repository\mysql\mysql-connector-java\8.0.15\mysql-connector-java-8.0.15.jar" />
	<context id="stuorg" targetRuntime="MyBatis3">
	
		<commentGenerator>
			<property name="suppressDate" value="true" />
			<!-- 是否去除自动生成的注释 true:是 : false:否 -->
			<property name="suppressAllComments" value="false" />
		</commentGenerator>
		
		<!--数据库链接URL,用户名、密码 -->
		<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
			connectionURL="jdbc:mysql://127.0.0.1/数据库名" userId="root"
			password="123456">
			<property name="nullCatalogMeansCurrent" value="true" />
		</jdbcConnection>
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>
		<!-- 生成模型的包名和位置 -->
		<javaModelGenerator targetPackage="com.lzy.domain"
			targetProject="src/main/java">
			<property name="enableSubPackages" value="true" />
			<property name="trimStrings" value="true" />
		</javaModelGenerator>
		<!-- 生成映射文件的包名和位置 -->
		<sqlMapGenerator targetPackage="mybatis"
			targetProject="src/main/resources">
			<property name="enableSubPackages" value="true" />
		</sqlMapGenerator>
		<!-- 生成DAO的包名和位置 -->
		<javaClientGenerator type="XMLMAPPER"
			targetPackage="com.lzy.mapper" targetProject="src/main/java">
			<property name="enableSubPackages" value="true" />
		</javaClientGenerator>
		<!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名 -->
		<table tableName="class" domainObjectName="Class"
			enableCountByExample="false" enableUpdateByExample="false"
			enableDeleteByExample="false" enableSelectByExample="false"
			selectByExampleQueryId="false"></table>
	</context>
</generatorConfiguration>

pom.xml文件添加依赖和插件:

        <!-- springboot-mybatis -->
		<dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-starter</artifactId>
			<version>2.1.2</version>
		</dependency>
		
		<!-- SpringBoot - MyBatis 逆向工程 -->
		<dependency>
		    <groupId>org.mybatis.generator</groupId>
		    <artifactId>mybatis-generator-core</artifactId>
		    <version>1.3.5</version>
		</dependency>
<!-- mybatis逆向生成 -->
			<plugin>
				<groupId>org.mybatis.generator</groupId>
				<artifactId>mybatis-generator-maven-plugin</artifactId>
				<configuration>
					<!-- 配置文件路径 -->
					<configurationFile>src/main/resources/generator/generatorConfig.xml</configurationFile>
					<!-- 允许覆盖生成的文件 -->
					<overwrite>true</overwrite>
					<!-- 允许移动生成的文件 -->
					<verbose>true</verbose>
				</configuration>
			</plugin>

properties文件记得配置连接数据库的信息,项目结构:

接下来就是运行惹:

项目右击run as

选择 maven build 随便一个,进入以后:

输入命令:mybatis-generator:generate ,运行

之后控制台报错:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:28 min
[INFO] Finished at: 2020-03-31T13:01:02+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.4.0:generate (default-cli) on project stuorg: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support. -> [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/MojoExecutionException

就是要去数据库设置一下那啥,timezone,进入数据库所在目录下的bin目录:

呜呜呜敲出你的cmd,回车:

 

输入命令 mysql -u root -p 

(用户root ,输入密码)

输入命令 show variables like ‘%time_zone%’;

(查看)

输入命令set global time_zone='+8:00';

设置时区,然后再回去eclipse重新run as:

控制台:

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.stuorg:stuorg:war:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.mybatis.generator:mybatis-generator-maven-plugin is missing. @ line 119, column 12
[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] -------------------------< com.stuorg:stuorg >--------------------------
[INFO] Building stuorg 0.0.1-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO] 
[INFO] --- mybatis-generator-maven-plugin:1.4.0:generate (default-cli) @ stuorg ---
[INFO] Connecting to the Database
[INFO] Introspecting table class
[INFO] Generating Record class for table class
[INFO] Generating Mapper Interface for table class
[INFO] Generating SQL Map for table class
[INFO] Saving file ClassMapper.xml
[INFO] Saving file Class.java
[INFO] Saving file ClassMapper.java
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.374 s
[INFO] Finished at: 2020-03-31T13:37:43+08:00
[INFO] ------------------------------------------------------------------------

然后刷新自己的项目,会发现目标小宝贝就有惹

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

asjodnobfy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值