当前位置: 首页>>代码示例>>Java>>正文


Java TopLevelClass.addField方法代码示例

本文整理汇总了Java中org.mybatis.generator.api.dom.java.TopLevelClass.addField方法的典型用法代码示例。如果您正苦于以下问题:Java TopLevelClass.addField方法的具体用法?Java TopLevelClass.addField怎么用?Java TopLevelClass.addField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mybatis.generator.api.dom.java.TopLevelClass的用法示例。


在下文中一共展示了TopLevelClass.addField方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makeSerializable

import org.mybatis.generator.api.dom.java.TopLevelClass; //导入方法依赖的package包/类
protected void makeSerializable(TopLevelClass topLevelClass,
                                IntrospectedTable introspectedTable) {
    if (addGWTInterface) {
        topLevelClass.addImportedType(gwtSerializable);
        topLevelClass.addSuperInterface(gwtSerializable);
    }

    if (!suppressJavaInterface) {
        topLevelClass.addImportedType(serializable);
        topLevelClass.addSuperInterface(serializable);

        Field field = new Field();
        field.setFinal(true);
        field.setInitializationString("1L");
        field.setName(SERIAL_VERSION_UID);
        field.setStatic(true);
        field.setType(new FullyQualifiedJavaType("long"));
        field.setVisibility(JavaVisibility.PRIVATE);
        context.getCommentGenerator().addFieldComment(field, introspectedTable);

        topLevelClass.addField(field);
    }
}
 
开发者ID:drtrang,项目名称:mybatis-generator-extension,代码行数:24,代码来源:SerializablePlugin.java

示例2: makeSerializable

import org.mybatis.generator.api.dom.java.TopLevelClass; //导入方法依赖的package包/类
protected void makeSerializable(TopLevelClass topLevelClass,
        IntrospectedTable introspectedTable) {
    if (addGWTInterface) {
        topLevelClass.addImportedType(gwtSerializable);
        topLevelClass.addSuperInterface(gwtSerializable);
    }
    
    if (!suppressJavaInterface) {
        topLevelClass.addImportedType(serializable);
        topLevelClass.addSuperInterface(serializable);

        Field field = new Field();
        field.setFinal(true);
        field.setInitializationString("1L"); //$NON-NLS-1$
        field.setName("serialVersionUID"); //$NON-NLS-1$
        field.setStatic(true);
        field.setType(new FullyQualifiedJavaType("long")); //$NON-NLS-1$
        field.setVisibility(JavaVisibility.PRIVATE);
        context.getCommentGenerator().addFieldComment(field, introspectedTable);

        topLevelClass.addField(field);
    }
}
 
开发者ID:xiachengwei5,项目名称:org.mybatis.generator.core-1.3.5,代码行数:24,代码来源:SerializablePlugin.java

示例3: getTopLevelClassShell

import org.mybatis.generator.api.dom.java.TopLevelClass; //导入方法依赖的package包/类
protected TopLevelClass getTopLevelClassShell() {
    FullyQualifiedJavaType interfaceType = new FullyQualifiedJavaType(
            introspectedTable.getDAOInterfaceType());
    FullyQualifiedJavaType implementationType = new FullyQualifiedJavaType(
            introspectedTable.getDAOImplementationType());

    CommentGenerator commentGenerator = context.getCommentGenerator();

    TopLevelClass answer = new TopLevelClass(implementationType);
    answer.setVisibility(JavaVisibility.PUBLIC);
    answer.setSuperClass(daoTemplate.getSuperClass());
    answer.addImportedType(daoTemplate.getSuperClass());
    answer.addSuperInterface(interfaceType);
    answer.addImportedType(interfaceType);

    for (FullyQualifiedJavaType fqjt : daoTemplate
            .getImplementationImports()) {
        answer.addImportedType(fqjt);
    }

    commentGenerator.addJavaFileComment(answer);

    // add constructor from the template
    answer.addMethod(daoTemplate.getConstructorClone(commentGenerator,
            implementationType, introspectedTable));

    // add any fields from the template
    for (Field field : daoTemplate.getFieldClones(commentGenerator,
            introspectedTable)) {
        answer.addField(field);
    }

    // add any methods from the template
    for (Method method : daoTemplate.getMethodClones(commentGenerator,
            introspectedTable)) {
        answer.addMethod(method);
    }

    return answer;
}
 
开发者ID:xiachengwei5,项目名称:org.mybatis.generator.core-1.3.5,代码行数:41,代码来源:DAOGenerator.java

示例4: modelBaseRecordClassGenerated

import org.mybatis.generator.api.dom.java.TopLevelClass; //导入方法依赖的package包/类
/**
 * 修改model
 */
@Override
public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
	Context context=introspectedTable.getContext();
	for (OneToOne oto : introspectedTable.getOneToOnes()) {
		String tableName = oto.getMappingTable();
		TableConfiguration tc =getMapTc(tableName, context);
		if (tc != null) {
			String pakkage = getModelPackage(introspectedTable, context);
			String domainName = tc.getDomainObjectName();
			String type=pakkage+"."+domainName;
			String fieldName = domainName.replaceFirst(new String(new char[] { domainName.charAt(0) }), new String(new char[] { domainName.charAt(0) }).toLowerCase());
			org.mybatis.generator.api.dom.java.Field field = new org.mybatis.generator.api.dom.java.Field();
			
			field.setName(fieldName);
			FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(type);
			field.setType(fqjt);
			field.setVisibility(JavaVisibility.PRIVATE);
			topLevelClass.addImportedType(new FullyQualifiedJavaType(type));
			topLevelClass.addField(field);

			// get
			Method getMethod = new Method();
			getMethod.setVisibility(JavaVisibility.PUBLIC);
			getMethod.setReturnType(fqjt);
			getMethod.setName("get" + tc.getDomainObjectName());
			getMethod.addBodyLine("return " + fieldName + ";");
			topLevelClass.addMethod(getMethod);
			// set
			Method setMethod = new Method();
			setMethod.setVisibility(JavaVisibility.PUBLIC);
			setMethod.setName("set" + tc.getDomainObjectName());
			setMethod.addParameter(new Parameter(new FullyQualifiedJavaType(type), fieldName));
			setMethod.addBodyLine("this." + fieldName + "=" + fieldName + ";");
			topLevelClass.addMethod(setMethod);
		}
	}
	return super.modelBaseRecordClassGenerated(topLevelClass, introspectedTable);
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:42,代码来源:OneToOnePlugin.java

示例5: getCompilationUnits

import org.mybatis.generator.api.dom.java.TopLevelClass; //导入方法依赖的package包/类
@Override
public List<CompilationUnit> getCompilationUnits() {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    progressCallback.startTask(getString(
            "Progress.7", table.toString())); //$NON-NLS-1$
    Plugin plugins = context.getPlugins();
    CommentGenerator commentGenerator = context.getCommentGenerator();

    TopLevelClass topLevelClass = new TopLevelClass(introspectedTable
            .getPrimaryKeyType());
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(topLevelClass);

    String rootClass = getRootClass();
    if (rootClass != null) {
        topLevelClass.setSuperClass(new FullyQualifiedJavaType(rootClass));
        topLevelClass.addImportedType(topLevelClass.getSuperClass());
    }

    for (IntrospectedColumn introspectedColumn : introspectedTable
            .getPrimaryKeyColumns()) {
        if (RootClassInfo.getInstance(rootClass, warnings)
                .containsProperty(introspectedColumn)) {
            continue;
        }

        Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
        if (plugins.modelFieldGenerated(field, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.PRIMARY_KEY)) {
            topLevelClass.addField(field);
            topLevelClass.addImportedType(field.getType());
        }

        Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
        if (plugins.modelGetterMethodGenerated(method, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.PRIMARY_KEY)) {
            topLevelClass.addMethod(method);
        }

        method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
        if (plugins.modelSetterMethodGenerated(method, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.PRIMARY_KEY)) {
            topLevelClass.addMethod(method);
        }
    }

    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    if (context.getPlugins().modelPrimaryKeyClassGenerated(
            topLevelClass, introspectedTable)) {
        answer.add(topLevelClass);
    }
    return answer;
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:57,代码来源:PrimaryKeyGenerator.java

示例6: getCompilationUnits

import org.mybatis.generator.api.dom.java.TopLevelClass; //导入方法依赖的package包/类
@Override
public List<CompilationUnit> getCompilationUnits() {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    progressCallback.startTask(getString("Progress.8", table.toString())); //$NON-NLS-1$
    Plugin plugins = context.getPlugins();
    CommentGenerator commentGenerator = context.getCommentGenerator();

    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getBaseRecordType());
    TopLevelClass topLevelClass = new TopLevelClass(type);
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(topLevelClass);

    FullyQualifiedJavaType superClass = getSuperClass();
    if (superClass != null) {
        topLevelClass.setSuperClass(superClass);
        topLevelClass.addImportedType(superClass);
    }

    commentGenerator.addModelClassComment(topLevelClass, introspectedTable);
    
    List<IntrospectedColumn> introspectedColumns = introspectedTable.getAllColumns();

    if (introspectedTable.isConstructorBased()) {
        addParameterizedConstructor(topLevelClass);

        if (!introspectedTable.isImmutable()) {
            addDefaultConstructor(topLevelClass);
        }
    }

    String rootClass = getRootClass();
    for (IntrospectedColumn introspectedColumn : introspectedColumns) {
        if (RootClassInfo.getInstance(rootClass, warnings)
                .containsProperty(introspectedColumn)) {
            continue;
        }

        Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
        if (plugins.modelFieldGenerated(field, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addField(field);
            topLevelClass.addImportedType(field.getType());
        }

        Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
        if (plugins.modelGetterMethodGenerated(method, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addMethod(method);
        }

        if (!introspectedTable.isImmutable()) {
            method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
            if (plugins.modelSetterMethodGenerated(method, topLevelClass,
                    introspectedColumn, introspectedTable,
                    Plugin.ModelClassType.BASE_RECORD)) {
                topLevelClass.addMethod(method);
            }
        }
    }

    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    if (context.getPlugins().modelBaseRecordClassGenerated(topLevelClass,
            introspectedTable)) {
        answer.add(topLevelClass);
    }
    return answer;
}
 
开发者ID:DomKing,项目名称:springbootWeb,代码行数:71,代码来源:SimpleModelGenerator.java

示例7: getCompilationUnits

import org.mybatis.generator.api.dom.java.TopLevelClass; //导入方法依赖的package包/类
@Override
public List<CompilationUnit> getCompilationUnits() {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    progressCallback.startTask(getString(
            "Progress.8", table.toString())); //$NON-NLS-1$
    Plugin plugins = context.getPlugins();
    CommentGenerator commentGenerator = context.getCommentGenerator();

    TopLevelClass topLevelClass = new TopLevelClass(introspectedTable
            .getBaseRecordType());
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(topLevelClass);

    FullyQualifiedJavaType superClass = getSuperClass();
    if (superClass != null) {
        topLevelClass.setSuperClass(superClass);
        topLevelClass.addImportedType(superClass);
    }

    List<IntrospectedColumn> introspectedColumns;
    if (includePrimaryKeyColumns()) {
        if (includeBLOBColumns()) {
            introspectedColumns = introspectedTable.getAllColumns();
        } else {
            introspectedColumns = introspectedTable.getNonBLOBColumns();
        }
    } else {
        if (includeBLOBColumns()) {
            introspectedColumns = introspectedTable
                    .getNonPrimaryKeyColumns();
        } else {
            introspectedColumns = introspectedTable.getBaseColumns();
        }
    }

    String rootClass = getRootClass();
    for (IntrospectedColumn introspectedColumn : introspectedColumns) {
        if (RootClassInfo.getInstance(rootClass, warnings)
                .containsProperty(introspectedColumn)) {
            continue;
        }

        Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
        if (plugins.modelFieldGenerated(field, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addField(field);
            topLevelClass.addImportedType(field.getType());
        }

        Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
        if (plugins.modelGetterMethodGenerated(method, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addMethod(method);
        }

        method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
        if (plugins.modelSetterMethodGenerated(method, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addMethod(method);
        }
    }

    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    if (context.getPlugins().modelBaseRecordClassGenerated(
            topLevelClass, introspectedTable)) {
        answer.add(topLevelClass);
    }
    return answer;
}
 
开发者ID:xiachengwei5,项目名称:org.mybatis.generator.core-1.3.5,代码行数:73,代码来源:BaseRecordGenerator.java

示例8: getCompilationUnits

import org.mybatis.generator.api.dom.java.TopLevelClass; //导入方法依赖的package包/类
@Override
public List<CompilationUnit> getCompilationUnits() {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    progressCallback.startTask(getString(
            "Progress.7", table.toString())); //$NON-NLS-1$
    Plugin plugins = context.getPlugins();
    CommentGenerator commentGenerator = context.getCommentGenerator();

    TopLevelClass topLevelClass = new TopLevelClass(introspectedTable
            .getPrimaryKeyType());
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(topLevelClass);

    String rootClass = getRootClass();
    if (rootClass != null) {
        topLevelClass.setSuperClass(new FullyQualifiedJavaType(rootClass));
        topLevelClass.addImportedType(topLevelClass.getSuperClass());
    }

    if (introspectedTable.isConstructorBased()) {
        addParameterizedConstructor(topLevelClass);
        
        if (!introspectedTable.isImmutable()) {
            addDefaultConstructor(topLevelClass);
        }
    }

    commentGenerator.addModelClassComment(topLevelClass, introspectedTable);

    for (IntrospectedColumn introspectedColumn : introspectedTable
            .getPrimaryKeyColumns()) {
        if (RootClassInfo.getInstance(rootClass, warnings)
                .containsProperty(introspectedColumn)) {
            continue;
        }

        Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
        if (plugins.modelFieldGenerated(field, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.PRIMARY_KEY)) {
            topLevelClass.addField(field);
            topLevelClass.addImportedType(field.getType());
        }

        Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
        if (plugins.modelGetterMethodGenerated(method, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.PRIMARY_KEY)) {
            topLevelClass.addMethod(method);
        }

        if (!introspectedTable.isImmutable()) {
            method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
            if (plugins.modelSetterMethodGenerated(method, topLevelClass,
                    introspectedColumn, introspectedTable,
                    Plugin.ModelClassType.PRIMARY_KEY)) {
                topLevelClass.addMethod(method);
            }
        }
    }

    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    if (context.getPlugins().modelPrimaryKeyClassGenerated(
            topLevelClass, introspectedTable)) {
        answer.add(topLevelClass);
    }
    return answer;
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:69,代码来源:PrimaryKeyGenerator.java

示例9: getCompilationUnits

import org.mybatis.generator.api.dom.java.TopLevelClass; //导入方法依赖的package包/类
@Override
public List<CompilationUnit> getCompilationUnits() {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    progressCallback.startTask(getString(
            "Progress.8", table.toString())); //$NON-NLS-1$
    Plugin plugins = context.getPlugins();
    CommentGenerator commentGenerator = context.getCommentGenerator();

    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getBaseRecordType());
    TopLevelClass topLevelClass = new TopLevelClass(type);
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(topLevelClass);

    FullyQualifiedJavaType superClass = getSuperClass();
    if (superClass != null) {
        topLevelClass.setSuperClass(superClass);
        topLevelClass.addImportedType(superClass);
    }
    commentGenerator.addModelClassComment(topLevelClass, introspectedTable);

    List<IntrospectedColumn> introspectedColumns = getColumnsInThisClass();

    if (introspectedTable.isConstructorBased()) {
        addParameterizedConstructor(topLevelClass, introspectedTable.getNonBLOBColumns());

        if(includeBLOBColumns()) {
            addParameterizedConstructor(topLevelClass, introspectedTable.getAllColumns());
        }

        if (!introspectedTable.isImmutable()) {
            addDefaultConstructor(topLevelClass);
        }
    }
    
    String rootClass = getRootClass();
    for (IntrospectedColumn introspectedColumn : introspectedColumns) {
        if (RootClassInfo.getInstance(rootClass, warnings)
                .containsProperty(introspectedColumn)) {
            continue;
        }

        Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
        if (plugins.modelFieldGenerated(field, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addField(field);
            topLevelClass.addImportedType(field.getType());
        }

        Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
        if (plugins.modelGetterMethodGenerated(method, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addMethod(method);
        }

        if (!introspectedTable.isImmutable()) {
            method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
            if (plugins.modelSetterMethodGenerated(method, topLevelClass,
                    introspectedColumn, introspectedTable,
                    Plugin.ModelClassType.BASE_RECORD)) {
                topLevelClass.addMethod(method);
            }
        }
    }

    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    if (context.getPlugins().modelBaseRecordClassGenerated(
            topLevelClass, introspectedTable)) {
        answer.add(topLevelClass);
    }
    return answer;
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:75,代码来源:BaseRecordGenerator.java

示例10: getCompilationUnits

import org.mybatis.generator.api.dom.java.TopLevelClass; //导入方法依赖的package包/类
@Override
public List<CompilationUnit> getCompilationUnits() {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    progressCallback.startTask(getString(
            "Progress.8", table.toString())); //$NON-NLS-1$
    Plugin plugins = context.getPlugins();
    CommentGenerator commentGenerator = context.getCommentGenerator();

    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getBaseRecordType());
    TopLevelClass topLevelClass = new TopLevelClass(type);
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(topLevelClass);

    FullyQualifiedJavaType superClass = getSuperClass();
    if (superClass != null) {
        topLevelClass.setSuperClass(superClass);
        topLevelClass.addImportedType(superClass);
    }
    commentGenerator.addModelClassComment(topLevelClass, introspectedTable);

    List<IntrospectedColumn> introspectedColumns = getColumnsInThisClass();

    if (introspectedTable.isConstructorBased()) {
        addParameterizedConstructor(topLevelClass);
        
        if (!introspectedTable.isImmutable()) {
            addDefaultConstructor(topLevelClass);
        }
    }
    
    String rootClass = getRootClass();
    for (IntrospectedColumn introspectedColumn : introspectedColumns) {
        if (RootClassInfo.getInstance(rootClass, warnings)
                .containsProperty(introspectedColumn)) {
            continue;
        }

        Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
        if (plugins.modelFieldGenerated(field, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addField(field);
            topLevelClass.addImportedType(field.getType());
        }

        Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
        if (plugins.modelGetterMethodGenerated(method, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addMethod(method);
        }

        if (!introspectedTable.isImmutable()) {
            method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
            if (plugins.modelSetterMethodGenerated(method, topLevelClass,
                    introspectedColumn, introspectedTable,
                    Plugin.ModelClassType.BASE_RECORD)) {
                topLevelClass.addMethod(method);
            }
        }
    }

    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    if (context.getPlugins().modelBaseRecordClassGenerated(
            topLevelClass, introspectedTable)) {
        answer.add(topLevelClass);
    }
    return answer;
}
 
开发者ID:DomKing,项目名称:springbootWeb,代码行数:71,代码来源:BaseRecordGenerator.java

示例11: getCompilationUnits

import org.mybatis.generator.api.dom.java.TopLevelClass; //导入方法依赖的package包/类
@Override
public List<CompilationUnit> getCompilationUnits() {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    progressCallback.startTask(getString("Progress.8", table.toString())); //$NON-NLS-1$
    Plugin plugins = context.getPlugins();
    CommentGenerator commentGenerator = context.getCommentGenerator();

    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getBaseRecordType());
    TopLevelClass topLevelClass = new TopLevelClass(type);
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(topLevelClass);

    FullyQualifiedJavaType superClass = getSuperClass();
    if (superClass != null) {
        topLevelClass.setSuperClass(superClass);
        topLevelClass.addImportedType(superClass);
    }


    // 注解
    topLevelClass.addAnnotation("@Data");

    // import
    topLevelClass.addImportedType("lombok.Data");

    commentGenerator.addModelClassComment(topLevelClass, introspectedTable);
    
    List<IntrospectedColumn> introspectedColumns = introspectedTable.getAllColumns();

    if (introspectedTable.isConstructorBased()) {
        addParameterizedConstructor(topLevelClass);

        if (!introspectedTable.isImmutable()) {
            addDefaultConstructor(topLevelClass);
        }
    }

    String rootClass = getRootClass();
    for (IntrospectedColumn introspectedColumn : introspectedColumns) {
        if (RootClassInfo.getInstance(rootClass, warnings)
                .containsProperty(introspectedColumn)) {
            continue;
        }

        Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
        if (plugins.modelFieldGenerated(field, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addField(field);
            topLevelClass.addImportedType(field.getType());
        }

        // 去掉getter setter 方法,使用 lombok

       /* Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
        if (plugins.modelGetterMethodGenerated(method, topLevelClass,
                introspectedColumn, introspectedTable,
                Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addMethod(method);
        }

        if (!introspectedTable.isImmutable()) {
            method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
            if (plugins.modelSetterMethodGenerated(method, topLevelClass,
                    introspectedColumn, introspectedTable,
                    Plugin.ModelClassType.BASE_RECORD)) {
                topLevelClass.addMethod(method);
            }
        }*/
    }

    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    if (context.getPlugins().modelBaseRecordClassGenerated(topLevelClass,
            introspectedTable)) {
        answer.add(topLevelClass);
    }
    return answer;
}
 
开发者ID:nextyu,项目名称:summer-mybatis-generator,代码行数:80,代码来源:SimpleModelGenerator.java


注:本文中的org.mybatis.generator.api.dom.java.TopLevelClass.addField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。