@Override
    public boolean modelFieldGenerated(Field field, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) {
    """
	具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
	@param field
	@param topLevelClass
	@param introspectedColumn
	@param introspectedTable
	@param modelClassType
	@return
    """
        if (this.logicalDeleteColumn != null) {
            // 常量、枚举和逻辑删除方法跟随 逻辑删除列走
            if (this.logicalDeleteColumn.getJavaProperty().equals(field.getName())) {
                // 1. 添加枚举
                if (PluginTools.getHook(ILogicalDeletePluginHook.class).logicalDeleteEnumGenerated(this.logicalDeleteColumn) == false) {
                    topLevelClass.addInnerEnum(this.logicalDeleteEnum);
                }
                // 2. andLogicalDeleted 方法
                Method mAndLogicalDeleted = JavaElementGeneratorTools.generateMethod(
                        METHOD_LOGICAL_DELETED,
                        JavaVisibility.PUBLIC,
                        null,
                        new Parameter(FullyQualifiedJavaType.getBooleanPrimitiveInstance(), "deleted")
                );
                commentGenerator.addGeneralMethodComment(mAndLogicalDeleted, introspectedTable);
                Method logicalDeleteSetter = JavaBeansUtil.getJavaBeansSetter(this.logicalDeleteColumn, context, introspectedTable);
                mAndLogicalDeleted.addBodyLine(logicalDeleteSetter.getName() + "(deleted ? " + this.getEnumConstantValue(true) + " : " + this.getEnumConstantValue(false) + ");");
                FormatTools.addMethodWithBestPosition(topLevelClass, mAndLogicalDeleted);

                // 3. 添加逻辑删除常量
                if (this.enableLogicalDeleteConst) {
                    Field logicalUnDeleteConstField = JavaElementGeneratorTools.generateStaticFinalField(
                            this.logicalUnDeleteConstName,
                            this.logicalDeleteColumn.getFullyQualifiedJavaType(),
                            this.getEnumConstantValue(false)
                    );
                    commentGenerator.addFieldComment(logicalUnDeleteConstField, introspectedTable);
                    Field logicalDeleteConstField = JavaElementGeneratorTools.generateStaticFinalField(
                            this.logicalDeleteConstName,
                            this.logicalDeleteColumn.getFullyQualifiedJavaType(),
                            this.getEnumConstantValue(true)
                    );
                    commentGenerator.addFieldComment(logicalDeleteConstField, introspectedTable);

                    // 常量放在字段开头
                    ArrayList<Field> fields = (ArrayList<Field>) topLevelClass.getFields();
                    fields.add(0, logicalUnDeleteConstField);
                    fields.add(0, logicalDeleteConstField);
                }
            }
        }
        return super.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, modelClassType);
    }
@Override
    public boolean modelFieldGenerated(Field field, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) {
        if (this.logicalDeleteColumn != null) {
            // 常量、枚举和逻辑删除方法跟随 逻辑删除列走
            if (this.logicalDeleteColumn.getJavaProperty().equals(field.getName())) {
                // 1. 添加枚举
                if (PluginTools.getHook(ILogicalDeletePluginHook.class).logicalDeleteEnumGenerated(this.logicalDeleteColumn) == false) {
                    topLevelClass.addInnerEnum(this.logicalDeleteEnum);
                }
                // 2. andLogicalDeleted 方法
                Method mAndLogicalDeleted = JavaElementGeneratorTools.generateMethod(
                        METHOD_LOGICAL_DELETED,
                        JavaVisibility.PUBLIC,
                        null,
                        new Parameter(FullyQualifiedJavaType.getBooleanPrimitiveInstance(), "deleted")
                );
                commentGenerator.addGeneralMethodComment(mAndLogicalDeleted, introspectedTable);
                Method logicalDeleteSetter = JavaBeansUtil.getJavaBeansSetter(this.logicalDeleteColumn, context, introspectedTable);
                mAndLogicalDeleted.addBodyLine(logicalDeleteSetter.getName() + "(deleted ? " + this.getEnumConstantValue(true) + " : " + this.getEnumConstantValue(false) + ");");
                FormatTools.addMethodWithBestPosition(topLevelClass, mAndLogicalDeleted);

                // 3. 添加逻辑删除常量
                if (this.enableLogicalDeleteConst) {
                    Field logicalUnDeleteConstField = JavaElementGeneratorTools.generateStaticFinalField(
                            this.logicalUnDeleteConstName,
                            this.logicalDeleteColumn.getFullyQualifiedJavaType(),
                            this.getEnumConstantValue(false)
                    );
                    commentGenerator.addFieldComment(logicalUnDeleteConstField, introspectedTable);
                    Field logicalDeleteConstField = JavaElementGeneratorTools.generateStaticFinalField(
                            this.logicalDeleteConstName,
                            this.logicalDeleteColumn.getFullyQualifiedJavaType(),
                            this.getEnumConstantValue(true)
                    );
                    commentGenerator.addFieldComment(logicalDeleteConstField, introspectedTable);

                    // 常量放在字段开头
                    ArrayList<Field> fields = (ArrayList<Field>) topLevelClass.getFields();
                    fields.add(0, logicalUnDeleteConstField);
                    fields.add(0, logicalDeleteConstField);
                }
            }
        }
        return super.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, modelClassType);
    }
@ Override public boolean modelFieldGenerated ( Field field , TopLevelClass topLevelClass , IntrospectedColumn introspectedColumn , IntrospectedTable introspectedTable , ModelClassType modelClassType ) { if ( this . logicalDeleteColumn != null ) { // 常量、枚举和逻辑删除方法跟随 逻辑删除列走 if ( this . logicalDeleteColumn . getJavaProperty ( ) . equals ( field . getName ( ) ) ) { // 1. 添加枚举 if ( PluginTools . getHook ( ILogicalDeletePluginHook . class ) . logicalDeleteEnumGenerated ( this . logicalDeleteColumn ) == false ) { topLevelClass . addInnerEnum ( this . logicalDeleteEnum ) ; } // 2. andLogicalDeleted 方法 Method mAndLogicalDeleted = JavaElementGeneratorTools . generateMethod ( METHOD_LOGICAL_DELETED , JavaVisibility . PUBLIC , null , new Parameter ( FullyQualifiedJavaType . getBooleanPrimitiveInstance ( ) , "deleted" ) ) ; commentGenerator . addGeneralMethodComment ( mAndLogicalDeleted , introspectedTable ) ; Method logicalDeleteSetter = JavaBeansUtil . getJavaBeansSetter ( this . logicalDeleteColumn , context , introspectedTable ) ; mAndLogicalDeleted . addBodyLine ( logicalDeleteSetter . getName ( ) + "(deleted ? " + this . getEnumConstantValue ( true ) + " : " + this . getEnumConstantValue ( false ) + ");" ) ; FormatTools . addMethodWithBestPosition ( topLevelClass , mAndLogicalDeleted ) ; // 3. 添加逻辑删除常量 if ( this . enableLogicalDeleteConst ) { Field logicalUnDeleteConstField = JavaElementGeneratorTools . generateStaticFinalField ( this . logicalUnDeleteConstName , this . logicalDeleteColumn . getFullyQualifiedJavaType ( ) , this . getEnumConstantValue ( false ) ) ; commentGenerator . addFieldComment ( logicalUnDeleteConstField , introspectedTable ) ; Field logicalDeleteConstField = JavaElementGeneratorTools . generateStaticFinalField ( this . logicalDeleteConstName , this . logicalDeleteColumn . getFullyQualifiedJavaType ( ) , this . getEnumConstantValue ( true ) ) ; commentGenerator . addFieldComment ( logicalDeleteConstField , introspectedTable ) ; // 常量放在字段开头 ArrayList < Field > fields = ( ArrayList < Field > ) topLevelClass . getFields ( ) ; fields . add ( 0 , logicalUnDeleteConstField ) ; fields . add ( 0 , logicalDeleteConstField ) ; } } } return super . modelFieldGenerated ( field , topLevelClass , introspectedColumn , introspectedTable , modelClassType ) ; }
具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
@param field
@param topLevelClass
@param introspectedColumn
@param introspectedTable
@param modelClassType
@return
具体执行顺序 http : // www . mybatis . org / generator / reference / pluggingIn . html