源码生成mybatis-generator-core-1.4.0-SNAPSHOT.jar方法

mybatis/generator 源码地址
mybatis/parent 源码地址
1. 分别点击Download ZIP下载到本地。
图片
图1

2. 解压generator-master.zip中的core到generator-master目录,然后解压parent-master.zip中的pom.xml到generator-master目录下
图2
3. 进入core目录,修改该目录下的pom.xml文件,将<relativePath />改成:<relativePath>../pom.xml</relativePath>

<parent>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-parent</artifactId>
    <version>31-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

4. 删除红箭头指向的三个文件和文件夹,然后在此目录下打开cmd执行命令:

mvn -N io.takari:maven:wrapper

会重新生成。
图4
5. 执行命令:

mvnw clean install -DskipTests

就会在本地仓库生成:
图5
图6

6. 测试:将mybatis-generator-core-1.4.0-SNAPSHOT.jar 和 generatorConfig.xml 拷贝到一个目录中。在目录中执行如下命令:

java -jar mybatis-generator-core-1.4.0-SNAPSHOT.jar -configfile generatorConfig.xml -overwrite

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="D:\**\**\mysql\mysql-connector-java\5.1.47\mysql-connector-java-5.1.47.jar" />
	<context id="DB2Tables" targetRuntime="MyBatis3">
		<commentGenerator>
			<property name="suppressAllComments" value="true" />
		</commentGenerator>
		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://localhost:3306/test?useSSL=false"
			userId="root" password="123456">
		</jdbcConnection>
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>
		<!--域模型层,生成的目标包,项目目标源文件 -->
		<javaModelGenerator targetPackage="com.pyg.pojo"
			targetProject="./">
			<property name="enableSubPackages" value="true" />
			<property name="trimStrings" value="true" />
		</javaModelGenerator>
		<!--XML映射文件,生成的位置(目标包),源代码文件夹 -->
		<sqlMapGenerator targetPackage="com.pyg.mapper"
			targetProject="./">
			<property name="enableSubPackages" value="true" />
		</sqlMapGenerator>
		<!--XML对应的Mapper类 -->
		<javaClientGenerator type="XMLMAPPER"
			targetPackage="com.pyg.mapper" targetProject="./">
			<property name="enableSubPackages" value="true" />
		</javaClientGenerator>
		<!-- 表名tb_item_cat,如果想要生成对应的类名为ItemCat,需要加domainObjectRenamingRule  -->
		<table schema="" tableName="tb_item_cat" 
			enableCountByExample="false" enableSelectByExample="false" 
			enableUpdateByExample="false" enableDeleteByExample="false">
			<domainObjectRenamingRule searchString="^Tb" replaceString=""/>
		</table>
		<!-- 多表一起生成  -->
		<!-- <table schema="" tableName="%" 
			enableCountByExample="false" enableSelectByExample="false" 
			enableUpdateByExample="false" enableDeleteByExample="false">
			<domainObjectRenamingRule searchString="^Tb" replaceString=""/>
		</table> -->
	</context>

</generatorConfiguration>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值