generator的自动生成实体类的注释

本文介绍了如何使用MyBatis Generator自定义CommentGenerator类,为生成的实体类添加注释。包括设置相关jar包、编写CommentGenerator实现类、执行生成类以及配置generatorConfig.xml文件来实现自动添加注释的功能。
摘要由CSDN通过智能技术生成

generator的自动生成实体类的注释

1,相关jar包
mybatis生成 jar包

 <groupId>org.mybatis.generator</groupId>
 <artifactId>mybatis-generator-core</artifactId>
 <version>1.3.2</version>

mysql jar包

 <groupId>mysql</groupId>
 <artifactId>mysql-connector-java</artifactId>
 <version>5.1.9</version>

2,自定义的CommentGenerator类
package cn.sc.util;

import static org.mybatis.generator.internal.util.StringUtility.isTrue;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

import org.mybatis.generator.api.CommentGenerator;
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.CompilationUnit;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.api.dom.java.InnerClass;
import org.mybatis.generator.api.dom.java.InnerEnum;
import org.mybatis.generator.api.dom.java.JavaElement;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.Parameter;
import org.mybatis.generator.api.dom.xml.XmlElement;
import org.mybatis.generator.config.MergeConstants;
import org.mybatis.generator.config.PropertyRegistry;

import static org.mybatis.generator.internal.util.StringUtility.isTrue;

public class MyCommentGenerator implements CommentGenerator {
private Properties properties;
private Properties systemPro;
private boolean suppressDate;
private boolean suppressAllComments;
private String currentDateStr;

public MyCommentGenerator() {
    super();
    properties = new Properties();
    systemPro = System.getProperties();
    suppressDate = false;
    suppressAllComments = false;
    currentDateStr = (new SimpleDateFormat("yyyy-MM-dd")).format(new Date());
}

public void addJavaFileComment(CompilationUnit compilationUnit) {
    // add no file level comments by default
    return;
}

/**
 * Adds a suitable comment to warn users that the element was generated, and
 * when it was generated.
 */
public void addComment(XmlElement xmlElement) {
    return;
}

public void addRootComment(XmlElement rootElement) {
    // add no document level comments by default
    return;
}

public void addConfigurationProperties(Properties properties) {
    this.properties.putAll(properties);

    suppressDate = isTrue(properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_SUPPRESS_DATE));

    suppressAllComments = isTrue(properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_SUPPRESS_ALL_COMMENTS));
}

/**
 * This method adds the custom javadoc tag for. You may do nothing if you do
 * not wish to include the Javadoc tag - however, if you do not include the
 * Javadoc tag then the Java merge capability of the eclipse plugin will
 * break.
 *
 * @param javaElement
 *     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值