src/main/java/com/itfsw/mybatis/generator/plugins/ExampleEnhancedPlugin.java
private void addOrderByMethodToExample(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
        // 添加orderBy
        Method orderByMethod = JavaElementGeneratorTools.generateMethod(
                "orderBy",
                JavaVisibility.PUBLIC,
                topLevelClass.getType(),
                new Parameter(FullyQualifiedJavaType.getStringInstance(), "orderByClause")
        );
        commentGenerator.addGeneralMethodComment(orderByMethod, introspectedTable);
        orderByMethod = JavaElementGeneratorTools.generateMethodBody(
                orderByMethod,
                "this.setOrderByClause(orderByClause);",
                "return this;"
        );
        FormatTools.addMethodWithBestPosition(topLevelClass, orderByMethod);
        logger.debug("itfsw(Example增强插件):" + topLevelClass.getType().getShortName() + "增加方法orderBy");

        // 添加orderBy
        Method orderByMethod1 = JavaElementGeneratorTools.generateMethod(
                "orderBy",
                JavaVisibility.PUBLIC,
                topLevelClass.getType(),
                new Parameter(FullyQualifiedJavaType.getStringInstance(), "orderByClauses", true)
        );
        commentGenerator.addGeneralMethodComment(orderByMethod1, introspectedTable);
        orderByMethod1 = JavaElementGeneratorTools.generateMethodBody(
                orderByMethod1,
                "StringBuffer sb = new StringBuffer();",
                "for (int i = 0; i < orderByClauses.length; i++) {",
                "sb.append(orderByClauses[i]);",
                "if (i < orderByClauses.length - 1) {",
                "sb.append(\" , \");",
                "}",
                "}",
                "this.setOrderByClause(sb.toString());",
                "return this;"
        );

        FormatTools.addMethodWithBestPosition(topLevelClass, orderByMethod1);
        logger.debug("itfsw(Example增强插件):" + topLevelClass.getType().getShortName() + "增加方法orderBy(String ... orderByClauses)");
    }
private void addOrderByMethodToExample(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
        // 添加orderBy
        Method orderByMethod = JavaElementGeneratorTools.generateMethod(
                "orderBy",
                JavaVisibility.PUBLIC,
                topLevelClass.getType(),
                new Parameter(FullyQualifiedJavaType.getStringInstance(), "orderByClause")
        );
        commentGenerator.addGeneralMethodComment(orderByMethod, introspectedTable);
        orderByMethod = JavaElementGeneratorTools.generateMethodBody(
                orderByMethod,
                "this.setOrderByClause(orderByClause);",
                "return this;"
        );
        FormatTools.addMethodWithBestPosition(topLevelClass, orderByMethod);
        logger.debug("itfsw(Example增强插件):" + topLevelClass.getType().getShortName() + "增加方法orderBy");

        // 添加orderBy
        Method orderByMethod1 = JavaElementGeneratorTools.generateMethod(
                "orderBy",
                JavaVisibility.PUBLIC,
                topLevelClass.getType(),
                new Parameter(FullyQualifiedJavaType.getStringInstance(), "orderByClauses", true)
        );
        commentGenerator.addGeneralMethodComment(orderByMethod1, introspectedTable);
        orderByMethod1 = JavaElementGeneratorTools.generateMethodBody(
                orderByMethod1,
                "StringBuffer sb = new StringBuffer();",
                "for (int i = 0; i < orderByClauses.length; i++) {",
                "sb.append(orderByClauses[i]);",
                "if (i < orderByClauses.length - 1) {",
                "sb.append(\" , \");",
                "}",
                "}",
                "this.setOrderByClause(sb.toString());",
                "return this;"
        );

        FormatTools.addMethodWithBestPosition(topLevelClass, orderByMethod1);
        logger.debug("itfsw(Example增强插件):" + topLevelClass.getType().getShortName() + "增加方法orderBy(String ... orderByClauses)");
    }
private void addOrderByMethodToExample ( TopLevelClass topLevelClass , IntrospectedTable introspectedTable ) { // 添加orderBy Method orderByMethod = JavaElementGeneratorTools . generateMethod ( "orderBy" , JavaVisibility . PUBLIC , topLevelClass . getType ( ) , new Parameter ( FullyQualifiedJavaType . getStringInstance ( ) , "orderByClause" ) ) ; commentGenerator . addGeneralMethodComment ( orderByMethod , introspectedTable ) ; orderByMethod = JavaElementGeneratorTools . generateMethodBody ( orderByMethod , "this.setOrderByClause(orderByClause);" , "return this;" ) ; FormatTools . addMethodWithBestPosition ( topLevelClass , orderByMethod ) ; logger . debug ( "itfsw(Example增强插件):" + topLe e Class.getType ( ).getSh o r t Name() + "增加 方 法 r erBy"); // 添加orderBy Method orderByMethod1 = JavaElementGeneratorTools . generateMethod ( "orderBy" , JavaVisibility . PUBLIC , topLevelClass . getType ( ) , new Parameter ( FullyQualifiedJavaType . getStringInstance ( ) , "orderByClauses" , true ) ) ; commentGenerator . addGeneralMethodComment ( orderByMethod1 , introspectedTable ) ; orderByMethod1 = JavaElementGeneratorTools . generateMethodBody ( orderByMethod1 , "StringBuffer sb = new StringBuffer();" , "for (int i = 0; i < orderByClauses.length; i++) {" , "sb.append(orderByClauses[i]);" , "if (i < orderByClauses.length - 1) {" , "sb.append(\" , \");" , "}" , "}" , "this.setOrderByClause(sb.toString());" , "return this;" ) ; FormatTools . addMethodWithBestPosition ( topLevelClass , orderByMethod1 ) ; logger . debug ( "itfsw(Example增强插件):" + topLe e Class.getType ( ).getSh o r t Name() + "增加 方 法 r erBy(String ... orderByClauses)"); }
Example增强了setOrderByClause方法，新增orderBy(String orderByClause)方法直接返回example，增强链式调用，可以一路.下去了。
@param topLevelClass
@param introspectedTable
Example增强了setOrderByClause方法，新增orderBy ( String orderByClause ) 方法直接返回example，增强链式调用，可以一路 . 下去了。