src/main/java/com/itfsw/mybatis/generator/plugins/OptimisticLockerPlugin.java
@Override
    public boolean modelBuilderSetterMethodGenerated(Method method, TopLevelClass topLevelClass, InnerClass builderClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable) {
        if (this.versionColumn != null && this.customizedNextVersion && introspectedColumn.getActualColumnName().equals(this.versionColumn.getActualColumnName())) {
            // nextVersion 方法
            Method nextVersion = JavaElementGeneratorTools.generateMethod(
                    METHOD_NEXT_VERSION,
                    JavaVisibility.PUBLIC,
                    builderClass.getType(),
                    new Parameter(this.versionColumn.getFullyQualifiedJavaType(), "version")
            );
            commentGenerator.addSetterComment(nextVersion, introspectedTable, this.versionColumn);

            Method setterMethod = JavaBeansUtil.getJavaBeansSetter(this.versionColumn, context, introspectedTable);

            JavaElementGeneratorTools.generateMethodBody(
                    nextVersion,
                    "obj." + setterMethod.getName() + "(version);",
                    "return this;"
            );

            FormatTools.addMethodWithBestPosition(builderClass, nextVersion);
        }

        return true;
    }
@Override
    public boolean modelBuilderSetterMethodGenerated(Method method, TopLevelClass topLevelClass, InnerClass builderClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable) {
        if (this.versionColumn != null && this.customizedNextVersion && introspectedColumn.getActualColumnName().equals(this.versionColumn.getActualColumnName())) {
            // nextVersion 方法
            Method nextVersion = JavaElementGeneratorTools.generateMethod(
                    METHOD_NEXT_VERSION,
                    JavaVisibility.PUBLIC,
                    builderClass.getType(),
                    new Parameter(this.versionColumn.getFullyQualifiedJavaType(), "version")
            );
            commentGenerator.addSetterComment(nextVersion, introspectedTable, this.versionColumn);

            Method setterMethod = JavaBeansUtil.getJavaBeansSetter(this.versionColumn, context, introspectedTable);

            JavaElementGeneratorTools.generateMethodBody(
                    nextVersion,
                    "obj." + setterMethod.getName() + "(version);",
                    "return this;"
            );

            FormatTools.addMethodWithBestPosition(builderClass, nextVersion);
        }

        return true;
    }
@ Override public boolean modelBuilderSetterMethodGenerated ( Method method , TopLevelClass topLevelClass , InnerClass builderClass , IntrospectedColumn introspectedColumn , IntrospectedTable introspectedTable ) { if ( this . versionColumn != null && this . customizedNextVersion && introspectedColumn . getActualColumnName ( ) . equals ( this . versionColumn . getActualColumnName ( ) ) ) { // nextVersion 方法 Method nextVersion = JavaElementGeneratorTools . generateMethod ( METHOD_NEXT_VERSION , JavaVisibility . PUBLIC , builderClass . getType ( ) , new Parameter ( this . versionColumn . getFullyQualifiedJavaType ( ) , "version" ) ) ; commentGenerator . addSetterComment ( nextVersion , introspectedTable , this . versionColumn ) ; Method setterMethod = JavaBeansUtil . getJavaBeansSetter ( this . versionColumn , context , introspectedTable ) ; JavaElementGeneratorTools . generateMethodBody ( nextVersion , "obj." + setterMethod . getName ( ) + "(version);" , "return this;" ) ; FormatTools . addMethodWithBestPosition ( builderClass , nextVersion ) ; } return true ; }
Model builder set 方法生成
@param method
@param topLevelClass
@param builderClass
@param introspectedColumn
@param introspectedTable
@return
Model builder set 方法生成