src/main/java/com/itfsw/mybatis/generator/plugins/SelectOneByExamplePlugin.java
@Override
    public boolean sqlMapSelectByExampleWithBLOBsElementGenerated(XmlElement element, IntrospectedTable introspectedTable) {
        // 生成查询语句
        XmlElement selectOneWithBLOBsElement = new XmlElement("select");
        // 添加注释(!!!必须添加注释，overwrite覆盖生成时，@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点，例子：@mbg.generated)
        commentGenerator.addComment(selectOneWithBLOBsElement);

        // 添加ID
        selectOneWithBLOBsElement.addAttribute(new Attribute("id", METHOD_SELECT_ONE_BY_EXAMPLE_WITH_BLOBS));
        // 添加返回类型
        selectOneWithBLOBsElement.addAttribute(new Attribute("resultMap", introspectedTable.getResultMapWithBLOBsId()));
        // 添加参数类型
        selectOneWithBLOBsElement.addAttribute(new Attribute("parameterType", introspectedTable.getExampleType()));
        // 添加查询SQL
        selectOneWithBLOBsElement.addElement(new TextElement("select"));

        StringBuilder sb = new StringBuilder();
        if (stringHasValue(introspectedTable.getSelectByExampleQueryId())) {
            sb.append('\'');
            sb.append(introspectedTable.getSelectByExampleQueryId());
            sb.append("' as QUERYID,");
            selectOneWithBLOBsElement.addElement(new TextElement(sb.toString()));
        }

        selectOneWithBLOBsElement.addElement(XmlElementGeneratorTools.getBaseColumnListElement(introspectedTable));
        selectOneWithBLOBsElement.addElement(new TextElement(","));
        selectOneWithBLOBsElement.addElement(XmlElementGeneratorTools.getBlobColumnListElement(introspectedTable));

        sb.setLength(0);
        sb.append("from ");
        sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
        selectOneWithBLOBsElement.addElement(new TextElement(sb.toString()));
        selectOneWithBLOBsElement.addElement(XmlElementGeneratorTools.getExampleIncludeElement(introspectedTable));

        XmlElement ifElement1 = new XmlElement("if");
        ifElement1.addAttribute(new Attribute("test", "orderByClause != null"));  //$NON-NLS-2$
        ifElement1.addElement(new TextElement("order by ${orderByClause}"));
        selectOneWithBLOBsElement.addElement(ifElement1);

        // 只查询一条
        selectOneWithBLOBsElement.addElement(new TextElement("limit 1"));

        this.selectOneByExampleWithBLOBsEle = selectOneWithBLOBsElement;
        return super.sqlMapSelectByExampleWithBLOBsElementGenerated(element, introspectedTable);
    }
@Override
    public boolean sqlMapSelectByExampleWithBLOBsElementGenerated(XmlElement element, IntrospectedTable introspectedTable) {
        // 生成查询语句
        XmlElement selectOneWithBLOBsElement = new XmlElement("select");
        // 添加注释(!!!必须添加注释，overwrite覆盖生成时，@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点，例子：@mbg.generated)
        commentGenerator.addComment(selectOneWithBLOBsElement);

        // 添加ID
        selectOneWithBLOBsElement.addAttribute(new Attribute("id", METHOD_SELECT_ONE_BY_EXAMPLE_WITH_BLOBS));
        // 添加返回类型
        selectOneWithBLOBsElement.addAttribute(new Attribute("resultMap", introspectedTable.getResultMapWithBLOBsId()));
        // 添加参数类型
        selectOneWithBLOBsElement.addAttribute(new Attribute("parameterType", introspectedTable.getExampleType()));
        // 添加查询SQL
        selectOneWithBLOBsElement.addElement(new TextElement("select"));

        StringBuilder sb = new StringBuilder();
        if (stringHasValue(introspectedTable.getSelectByExampleQueryId())) {
            sb.append('\'');
            sb.append(introspectedTable.getSelectByExampleQueryId());
            sb.append("' as QUERYID,");
            selectOneWithBLOBsElement.addElement(new TextElement(sb.toString()));
        }

        selectOneWithBLOBsElement.addElement(XmlElementGeneratorTools.getBaseColumnListElement(introspectedTable));
        selectOneWithBLOBsElement.addElement(new TextElement(","));
        selectOneWithBLOBsElement.addElement(XmlElementGeneratorTools.getBlobColumnListElement(introspectedTable));

        sb.setLength(0);
        sb.append("from ");
        sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
        selectOneWithBLOBsElement.addElement(new TextElement(sb.toString()));
        selectOneWithBLOBsElement.addElement(XmlElementGeneratorTools.getExampleIncludeElement(introspectedTable));

        XmlElement ifElement1 = new XmlElement("if");
        ifElement1.addAttribute(new Attribute("test", "orderByClause != null"));  //$NON-NLS-2$
        ifElement1.addElement(new TextElement("order by ${orderByClause}"));
        selectOneWithBLOBsElement.addElement(ifElement1);

        // 只查询一条
        selectOneWithBLOBsElement.addElement(new TextElement("limit 1"));

        this.selectOneByExampleWithBLOBsEle = selectOneWithBLOBsElement;
        return super.sqlMapSelectByExampleWithBLOBsElementGenerated(element, introspectedTable);
    }
@ Override public boolean sqlMapSelectByExampleWithBLOBsElementGenerated ( XmlElement element , IntrospectedTable introspectedTable ) { // 生成查询语句 XmlElement selectOneWithBLOBsElement = new XmlElement ( "select" ) ; // 添加注释(!!!必须添加注释，overwrite覆盖生成时，@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点，例子：@mbg.generated) commentGenerator . addComment ( selectOneWithBLOBsElement ) ; // 添加ID selectOneWithBLOBsElement . addAttribute ( new Attribute ( "id" , METHOD_SELECT_ONE_BY_EXAMPLE_WITH_BLOBS ) ) ; // 添加返回类型 selectOneWithBLOBsElement . addAttribute ( new Attribute ( "resultMap" , introspectedTable . getResultMapWithBLOBsId ( ) ) ) ; // 添加参数类型 selectOneWithBLOBsElement . addAttribute ( new Attribute ( "parameterType" , introspectedTable . getExampleType ( ) ) ) ; // 添加查询SQL selectOneWithBLOBsElement . addElement ( new TextElement ( "select" ) ) ; StringBuilder sb = new StringBuilder ( ) ; if ( stringHasValue ( introspectedTable . getSelectByExampleQueryId ( ) ) ) { sb . append ( ' ' ) ; sb . append ( introspectedTable . getSelectByExampleQueryId ( ) ) ; sb . append ( "' as QUERYID," ) ; selectOneWithBLOBsElement . addElement ( new TextElement ( sb . toString ( ) ) ) ; } selectOneWithBLOBsElement . addElement ( XmlElementGeneratorTools . getBaseColumnListElement ( introspectedTable ) ) ; selectOneWithBLOBsElement . addElement ( new TextElement ( "," ) ) ; selectOneWithBLOBsElement . addElement ( XmlElementGeneratorTools . getBlobColumnListElement ( introspectedTable ) ) ; sb . setLength ( 0 ) ; sb . append ( "from " ) ; sb . append ( introspectedTable . getAliasedFullyQualifiedTableNameAtRuntime ( ) ) ; selectOneWithBLOBsElement . addElement ( new TextElement ( sb . toString ( ) ) ) ; selectOneWithBLOBsElement . addElement ( XmlElementGeneratorTools . getExampleIncludeElement ( introspectedTable ) ) ; XmlElement ifElement1 = new XmlElement ( "if" ) ; ifElement1 . addAttribute ( new Attribute ( "test" , "orderByClause != null" ) ) ; //$NON-NLS-2$ ifElement1 . addElement ( new TextElement ( "order by ${orderByClause}" ) ) ; selectOneWithBLOBsElement . addElement ( ifElement1 ) ; // 只查询一条 selectOneWithBLOBsElement . addElement ( new TextElement ( "limit 1" ) ) ; this . selectOneByExampleWithBLOBsEle = selectOneWithBLOBsElement ; return super . sqlMapSelectByExampleWithBLOBsElementGenerated ( element , introspectedTable ) ; }
具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
@param element
@param introspectedTable
@return
具体执行顺序 http : // www . mybatis . org / generator / reference / pluggingIn . html