zoukankan      html  css  js  c++  java
  • 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:devReporsitorymysqlmysql-connector-java5.1.38mysql-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;

     本篇为原创内容:转载请注明出处

    【一位十年码农的碎碎念,扫码关注获取更多精彩内容】

    成长的乐趣,在于分享!
    大龄程序员,一路走来,感慨颇多。闲暇时写写字,希望能给同行人一点帮助。
    本文版权归作者growithus和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    用python实现简单的调度场算法
    数据结构顺序表python
    数据结构顺序表C
    python绘制5角形,6角星方法
    TsinghuaX+00740043_2X C++程序设计进阶 C7-3
    Struts2开发环境搭建,及一个简单登录功能实例
    Javascript进度条
    java.util.Date与java.sql.Date
    Error while performing database login with the sqljdbc driver:Unable to create connection. Check your URL.
    java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 在指定的 DSN 中,驱动程序和应用程序之间的体系结构不匹配
  • 原文地址:https://www.cnblogs.com/growithus/p/11012240.html
Copyright © 2011-2022 走看看