mybatis-generator命令行生成代码

目录文件如下:

generator.xml文件如下:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
 3 <generatorConfiguration>
 4     <!-- 数据库驱动包位置 -->
 5     <classPathEntry location="E:\generator\mysql-connector-java-5.1.34.jar" /> 
 6     <!-- <classPathEntry location="C:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar" />-->
 7     <context id="DB2Tables" targetRuntime="MyBatis3">
 8         <commentGenerator>
 9             <property name="suppressAllComments" value="true" />
10         </commentGenerator>
11         <!-- 数据库链接URL、用户名、密码 -->
12          <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/new_taozugong" userId="root" password="root"> 
13         <!--<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="msa" password="msa">-->
14         </jdbcConnection>
15         <javaTypeResolver>
16             <property name="forceBigDecimals" value="false" />
17         </javaTypeResolver>
18         <!-- 生成模型的包名和位置 -->
19         <javaModelGenerator targetPackage="com.taozugong.admin.common.entity" targetProject="E:\generator\src">
20             <property name="enableSubPackages" value="true" />
21             <property name="trimStrings" value="true" />
22         </javaModelGenerator>
23         <!-- 生成的映射文件包名和位置 -->
24         <sqlMapGenerator targetPackage="mybatis.mapper" targetProject="E:\generator\src">
25             <property name="enableSubPackages" value="true" />
26         </sqlMapGenerator>
27         <!-- 生成DAO的包名和位置 -->
28         <javaClientGenerator type="XMLMAPPER" targetPackage="com.taozugong.admin.dao.mapper" targetProject="E:\generator\src">
29             <property name="enableSubPackages" value="true" />
30         </javaClientGenerator>
31         <!-- 要生成那些表(更改tableName和domainObjectName就可以) -->
32 
33         <table tableName="activity" domainObjectName="Activity" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
34         <table tableName="activity_help_record" domainObjectName="activityHelpRecord" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
35         <table tableName="activity_product_setting" domainObjectName="activityProductSetting" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
36         <table tableName="activity_product_template" domainObjectName="activityProductTemplate" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
37         <table tableName="activity_record" domainObjectName="activityRecord" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
38     </context>
39     
40 </generatorConfiguration>

直接cmd输入如下命令即可生成

java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite

转载于:https://www.cnblogs.com/walblog/p/9789814.html

Mybatis-generator是一个自动生成MyBatis代码的工具,可以快速生成Mapper、Dao、Entity等代码文件,可大大提高开发效率。如果需要多个项目使用相同的生成器配置,我们可以将该生成器打包成jar包,以供其他项目引用。 首先,在生成器的pom.xml文件中添加以下代码,将生成器打包成jar包: ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.1.1</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>org.mybatis.generator.api.ShellRunner</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build> ``` 需要注意的是,这里需要指定MainClass为org.mybatis.generator.api.ShellRunner。 然后,执行以下Maven命令打包即可: ```bash mvn clean package ``` 生成的jar包位于target文件夹下。 接下来,我们可以将生成的jar包引入到其他项目中,在其他项目的pom.xml文件中添加以下依赖: ```xml <dependencies> <dependency> <groupId>com.company</groupId> <artifactId>mybatis-generator</artifactId> <version>1.0-SNAPSHOT</version> <scope>provided</scope> </dependency> </dependencies> ``` 其中,groupId和artifactId需要根据实际项目名称进行修改,version则要对应生成的jar包版本号。 最后,在其他项目中,可以通过在命令行中执行以下命令运行自定义生成器: ```bash java -jar mybatis-generator.jar -configfile generatorConfig.xml -overwrite ``` 其中,generatorConfig.xml为自定义的生成器配置文件,-overwrite表示覆盖已存在的文件。 通过以上步骤,我们就可以自定义Mybatis-generator生成器并将其打包成jar包,以供其他项目引用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值