src/main/java/com/itfsw/mybatis/generator/plugins/LogicalDeletePlugin.java
@Override
    public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
        if (this.logicalDeleteColumn != null) {
            // 引入 Model类
            topLevelClass.addImportedType(this.getColumnInModelType());

            List<InnerClass> innerClasses = topLevelClass.getInnerClasses();
            for (InnerClass innerClass : innerClasses) {
                if ("Criteria".equals(innerClass.getType().getShortName())) {
                    // 增加逻辑删除条件
                    Method method = new Method(METHOD_LOGICAL_DELETED);
                    commentGenerator.addGeneralMethodComment(method, introspectedTable);
                    method.setVisibility(JavaVisibility.PUBLIC);
                    method.setReturnType(innerClass.getType());
                    method.addParameter(new Parameter(FullyQualifiedJavaType.getBooleanPrimitiveInstance(), "deleted"));

                    StringBuffer sb = new StringBuffer();
                    sb.append("return deleted ? ");

                    String modelName = this.getColumnInModelType().getShortName();

                    // 调用EqualTo方法
                    StringBuilder equalToMethodName = new StringBuilder();
                    equalToMethodName.append(this.logicalDeleteColumn.getJavaProperty());
                    equalToMethodName.setCharAt(0, Character.toUpperCase(equalToMethodName.charAt(0)));
                    equalToMethodName.insert(0, "and");
                    equalToMethodName.append("EqualTo");
                    sb.append(equalToMethodName);
                    sb.append("(" + modelName + "." + this.getEnumConstantValue(true) + ")");

                    sb.append(" : ");

                    // 调用NotEqualTo 方法
                    StringBuilder notEqualToMethodName = new StringBuilder();
                    notEqualToMethodName.append(this.logicalDeleteColumn.getJavaProperty());
                    notEqualToMethodName.setCharAt(0, Character.toUpperCase(notEqualToMethodName.charAt(0)));
                    notEqualToMethodName.insert(0, "and");
                    notEqualToMethodName.append("NotEqualTo");
                    sb.append(notEqualToMethodName);
                    sb.append("(" + modelName + "." + this.getEnumConstantValue(true) + ")");

                    sb.append(";");

                    method.addBodyLine(sb.toString());

                    FormatTools.addMethodWithBestPosition(innerClass, method);
                }
            }
        }
        return super.modelExampleClassGenerated(topLevelClass, introspectedTable);
    }
@Override
    public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
        if (this.logicalDeleteColumn != null) {
            // 引入 Model类
            topLevelClass.addImportedType(this.getColumnInModelType());

            List<InnerClass> innerClasses = topLevelClass.getInnerClasses();
            for (InnerClass innerClass : innerClasses) {
                if ("Criteria".equals(innerClass.getType().getShortName())) {
                    // 增加逻辑删除条件
                    Method method = new Method(METHOD_LOGICAL_DELETED);
                    commentGenerator.addGeneralMethodComment(method, introspectedTable);
                    method.setVisibility(JavaVisibility.PUBLIC);
                    method.setReturnType(innerClass.getType());
                    method.addParameter(new Parameter(FullyQualifiedJavaType.getBooleanPrimitiveInstance(), "deleted"));

                    StringBuffer sb = new StringBuffer();
                    sb.append("return deleted ? ");

                    String modelName = this.getColumnInModelType().getShortName();

                    // 调用EqualTo方法
                    StringBuilder equalToMethodName = new StringBuilder();
                    equalToMethodName.append(this.logicalDeleteColumn.getJavaProperty());
                    equalToMethodName.setCharAt(0, Character.toUpperCase(equalToMethodName.charAt(0)));
                    equalToMethodName.insert(0, "and");
                    equalToMethodName.append("EqualTo");
                    sb.append(equalToMethodName);
                    sb.append("(" + modelName + "." + this.getEnumConstantValue(true) + ")");

                    sb.append(" : ");

                    // 调用NotEqualTo 方法
                    StringBuilder notEqualToMethodName = new StringBuilder();
                    notEqualToMethodName.append(this.logicalDeleteColumn.getJavaProperty());
                    notEqualToMethodName.setCharAt(0, Character.toUpperCase(notEqualToMethodName.charAt(0)));
                    notEqualToMethodName.insert(0, "and");
                    notEqualToMethodName.append("NotEqualTo");
                    sb.append(notEqualToMethodName);
                    sb.append("(" + modelName + "." + this.getEnumConstantValue(true) + ")");

                    sb.append(";");

                    method.addBodyLine(sb.toString());

                    FormatTools.addMethodWithBestPosition(innerClass, method);
                }
            }
        }
        return super.modelExampleClassGenerated(topLevelClass, introspectedTable);
    }
@ Override public boolean modelExampleClassGenerated ( TopLevelClass topLevelClass , IntrospectedTable introspectedTable ) { if ( this . logicalDeleteColumn != null ) { // 引入 Model类 topLevelClass . addImportedType ( this . getColumnInModelType ( ) ) ; List < InnerClass > innerClasses = topLevelClass . getInnerClasses ( ) ; for ( InnerClass innerClass : innerClasses ) { if ( "Criteria" . equals ( innerClass . getType ( ) . getShortName ( ) ) ) { // 增加逻辑删除条件 Method method = new Method ( METHOD_LOGICAL_DELETED ) ; commentGenerator . addGeneralMethodComment ( method , introspectedTable ) ; method . setVisibility ( JavaVisibility . PUBLIC ) ; method . setReturnType ( innerClass . getType ( ) ) ; method . addParameter ( new Parameter ( FullyQualifiedJavaType . getBooleanPrimitiveInstance ( ) , "deleted" ) ) ; StringBuffer sb = new StringBuffer ( ) ; sb . append ( "return deleted ? " ) ; String modelName = this . getColumnInModelType ( ) . getShortName ( ) ; // 调用EqualTo方法 StringBuilder equalToMethodName = new StringBuilder ( ) ; equalToMethodName . append ( this . logicalDeleteColumn . getJavaProperty ( ) ) ; equalToMethodName . setCharAt ( 0 , Character . toUpperCase ( equalToMethodName . charAt ( 0 ) ) ) ; equalToMethodName . insert ( 0 , "and" ) ; equalToMethodName . append ( "EqualTo" ) ; sb . append ( equalToMethodName ) ; sb . append ( "(" + modelName + "." + this . getEnumConstantValue ( true ) + ")" ) ; sb . append ( " : " ) ; // 调用NotEqualTo 方法 StringBuilder notEqualToMethodName = new StringBuilder ( ) ; notEqualToMethodName . append ( this . logicalDeleteColumn . getJavaProperty ( ) ) ; notEqualToMethodName . setCharAt ( 0 , Character . toUpperCase ( notEqualToMethodName . charAt ( 0 ) ) ) ; notEqualToMethodName . insert ( 0 , "and" ) ; notEqualToMethodName . append ( "NotEqualTo" ) ; sb . append ( notEqualToMethodName ) ; sb . append ( "(" + modelName + "." + this . getEnumConstantValue ( true ) + ")" ) ; sb . append ( ";" ) ; method . addBodyLine ( sb . toString ( ) ) ; FormatTools . addMethodWithBestPosition ( innerClass , method ) ; } } } return super . modelExampleClassGenerated ( topLevelClass , introspectedTable ) ; }
ModelExample Methods 生成
具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
@param topLevelClass
@param introspectedTable
@return
ModelExample Methods 生成 具体执行顺序 http : // www . mybatis . org / generator / reference / pluggingIn . html