mybatis-generator生成数据表中注释
0、git clone https://github.com/backkoms/mybatis-generator-comments.git,编译打包,install到本地或delopy私服库中均可。
1、pom.xml配置
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>utf8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>
${basedir}/src/test/resources/conf/generatorConfig.xml
</configurationFile>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>com.zhishi.mybatis</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
2、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="C:\dev\Reporsitory\mysql\mysql-connector-java\5.1.38\mysql-connector-java-5.1.38.jar" /> <context id="context" targetRuntime="MyBatis3"> <plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin"> <property name="searchString" value="Example$" /> <property name="replaceString" value="Criteria" /> </plugin> <plugin type="org.mybatis.generator.plugins.CachePlugin"> <property name="cache_eviction" value="LRU" /> <property name="cache_flushInterval" value="60000" /> <property name="cache_readOnly" value="true" /> <property name="cache_size" value="1560" /> </plugin> <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"></plugin> <plugin type="org.mybatis.generator.plugins.SerializablePlugin"> <property name="suppressJavaInterface" value="false" /> </plugin> <commentGenerator type="org.mybatis.generator.internal.CustomeCommentGenerator"><!-- 数据库表注释生成-- > <property name="javaFileEncoding" value="UTF-8" /> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <property name="suppressAllComments" value="false" /> <property name="suppressDate" value="false" /> </commentGenerator> <!-- 请填写connectionURL、userId、password --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://192.168.1.102:3306/loan" userId="root" password="root" /> <!-- 生成持久化对象 --> <javaModelGenerator targetPackage="com.zhishi.domain" targetProject="src/test/java"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- 生成mapper.xml文件 --> <sqlMapGenerator targetPackage="mapper/mybatis" targetProject="src/test/resources"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <!-- 生成Mapper接口 --> <javaClientGenerator targetPackage="com.zhishi.dal.mapper.credit" targetProject="src/main/java" type="XMLMAPPER"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <!-- 需要生成的数据库表 --> <table tableName="tb_trx_bank" domainObjectName="TrxBank"> <generatedKey column="tid" sqlStatement=" select replace(uuid(),'-','')" /><!-- 主键为uuid的情况,自动生成-- > </table> </context> </generatorConfiguration>
2、eclipse中Run as --> maven build .... -->Goals中输入命令行:mybatis-generator:generate -e
3、查看生成的文件
/**
* 主键
* 表 : tb_trx_bank
* 对应字段 : tid
*/
private String tid;
/**
* 交易类型
* 表 : tb_trx_bank
* 对应字段 : type
*/
private String type;
本篇为原创内容:转载请注明出处
【一位十年码农的碎碎念,扫码关注获取更多精彩内容】
成长的乐趣,在于分享!
|