All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mybatis.generator.api.plus.MybatisPluginComment Maven / Gradle / Ivy

package org.mybatis.generator.api.plus;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.api.dom.xml.*;

import java.text.SimpleDateFormat;
import java.util.*;


/**
 * @author wangfupeng
 */
public class MybatisPluginComment extends PluginAdapter {


    private FullyQualifiedJavaType apiModel;
    private FullyQualifiedJavaType apiModelProperty;
    private boolean addGWTInterface;
    private boolean suppressJavaInterface;
    private FullyQualifiedJavaType data;
    private FullyQualifiedJavaType noArgsConstructor;
    private FullyQualifiedJavaType builder;
    private FullyQualifiedJavaType allArgsConstructor;

    public MybatisPluginComment() {
        super();
        apiModel = new FullyQualifiedJavaType("io.swagger.annotations.ApiModel");
        apiModelProperty = new FullyQualifiedJavaType("io.swagger.annotations.ApiModelProperty");
        allArgsConstructor = new FullyQualifiedJavaType("lombok.AllArgsConstructor");
        builder = new FullyQualifiedJavaType("lombok.Builder");
        data = new FullyQualifiedJavaType("lombok.Data");
        noArgsConstructor = new FullyQualifiedJavaType("lombok.NoArgsConstructor");
    }

    @Override
    public boolean validate(List warnings) {
        return true;
    }

    @Override
    public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass,
                                                 IntrospectedTable introspectedTable) {
        topLevelClass.getJavaDocLines().clear();
        topLevelClass.addImportedType(apiModel);
        topLevelClass.addImportedType(apiModelProperty);
        topLevelClass.addImportedType(data);
        topLevelClass.addImportedType(builder);
        topLevelClass.addImportedType(allArgsConstructor);
        topLevelClass.addImportedType(noArgsConstructor);
        topLevelClass.addAnnotation("@ApiModel(\"" + introspectedTable.getRemarks() + "\")");
        topLevelClass.addAnnotation("@Data");
        topLevelClass.addAnnotation("@Builder");
        topLevelClass.addAnnotation("@NoArgsConstructor");
        topLevelClass.addAnnotation("@AllArgsConstructor");
        return true;
    }

    @Override
    public boolean modelFieldGenerated(Field field,
                                       TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn,
                                       IntrospectedTable introspectedTable, ModelClassType modelClassType) {
        field.getJavaDocLines().clear();
        field.addJavaDocLine("/**");
        field.addJavaDocLine(" * Remark:    " + introspectedColumn.getRemarks());
        field.addJavaDocLine(" * Table:     " + introspectedTable.getFullyQualifiedTable());
        field.addJavaDocLine(" * Column:    " + introspectedColumn.getActualColumnName());
        field.addJavaDocLine(" * Nullable:  " + introspectedColumn.isNullable());
        field.addJavaDocLine(" */");
        field.addAnnotation("@ApiModelProperty(\"" + introspectedColumn.getRemarks().replaceAll("\"", "“") + "\")");
        return true;
    }

    @Override
    public boolean modelGetterMethodGenerated(Method method,
                                              TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn,
                                              IntrospectedTable introspectedTable, ModelClassType modelClassType) {
        method.getJavaDocLines().clear();
        return true;
    }

    @Override
    public boolean modelSetterMethodGenerated(Method method,
                                              TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn,
                                              IntrospectedTable introspectedTable, ModelClassType modelClassType) {
        method.getJavaDocLines().clear();
        return true;
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy