src/main/java/com/itfsw/mybatis/generator/plugins/SelectSelectivePlugin.java
private XmlElement generateSelectSelectiveElement(String id, IntrospectedTable introspectedTable, boolean selectOne, boolean byExample) {
        XmlElement selectSelectiveEle = new XmlElement("select");
        commentGenerator.addComment(selectSelectiveEle);

        selectSelectiveEle.addAttribute(new Attribute("id", id));
        // issues#16
        if (introspectedTable.isConstructorBased()) {
            selectSelectiveEle.addAttribute(new Attribute("resultMap", ID_FOR_PROPERTY_BASED_RESULT_MAP));
        } else if (introspectedTable.hasBLOBColumns()) {
            selectSelectiveEle.addAttribute(new Attribute("resultMap", introspectedTable.getResultMapWithBLOBsId()));
        } else {
            selectSelectiveEle.addAttribute(new Attribute("resultMap", introspectedTable.getBaseResultMapId()));
        }
        selectSelectiveEle.addAttribute(new Attribute("parameterType", "map"));

        if (byExample) {
            selectSelectiveEle.addElement(new TextElement("select"));
            if (stringHasValue(introspectedTable.getSelectByExampleQueryId())) {
                selectSelectiveEle.addElement(new TextElement("'" + introspectedTable.getSelectByExampleQueryId() + "' as QUERYID,"));
            }

            if (!selectOne) {
                // issues#20
                XmlElement ifDistinctElement = new XmlElement("if");
                ifDistinctElement.addAttribute(new Attribute("test", "example.distinct"));
                ifDistinctElement.addElement(new TextElement("distinct"));
                selectSelectiveEle.addElement(ifDistinctElement);
            }
        } else {
            selectSelectiveEle.addElement(new TextElement("select"));
            if (stringHasValue(introspectedTable.getSelectByPrimaryKeyQueryId())) {
                selectSelectiveEle.addElement(new TextElement("'" + introspectedTable.getSelectByPrimaryKeyQueryId() + "' as QUERYID,"));
            }
        }

        selectSelectiveEle.addElement(this.generateSelectiveElement(introspectedTable));
        selectSelectiveEle.addElement(new TextElement("from " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()));

        if (byExample) {
            selectSelectiveEle.addElement(XmlElementGeneratorTools.getUpdateByExampleIncludeElement(introspectedTable));

            XmlElement ifElement1 = new XmlElement("if");
            ifElement1.addAttribute(new Attribute("test", "example.orderByClause != null"));
            ifElement1.addElement(new TextElement("order by ${example.orderByClause}"));
            selectSelectiveEle.addElement(ifElement1);
        } else {
            boolean and = false;
            StringBuffer sb = new StringBuffer();
            for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
                sb.setLength(0);
                if (and) {
                    sb.append("  and ");
                } else {
                    sb.append("where ");
                    and = true;
                }

                sb.append(MyBatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
                sb.append(" = ");
                sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, introspectedTable.getRules().generatePrimaryKeyClass() ? "record." : null));
                selectSelectiveEle.addElement(new TextElement(sb.toString()));
            }
        }

        if (selectOne) {
            // 只查询一条
            selectSelectiveEle.addElement(new TextElement("limit 1"));
        }

        return selectSelectiveEle;
    }
private XmlElement generateSelectSelectiveElement(String id, IntrospectedTable introspectedTable, boolean selectOne, boolean byExample) {
        XmlElement selectSelectiveEle = new XmlElement("select");
        commentGenerator.addComment(selectSelectiveEle);

        selectSelectiveEle.addAttribute(new Attribute("id", id));
        // issues#16
        if (introspectedTable.isConstructorBased()) {
            selectSelectiveEle.addAttribute(new Attribute("resultMap", ID_FOR_PROPERTY_BASED_RESULT_MAP));
        } else if (introspectedTable.hasBLOBColumns()) {
            selectSelectiveEle.addAttribute(new Attribute("resultMap", introspectedTable.getResultMapWithBLOBsId()));
        } else {
            selectSelectiveEle.addAttribute(new Attribute("resultMap", introspectedTable.getBaseResultMapId()));
        }
        selectSelectiveEle.addAttribute(new Attribute("parameterType", "map"));

        if (byExample) {
            selectSelectiveEle.addElement(new TextElement("select"));
            if (stringHasValue(introspectedTable.getSelectByExampleQueryId())) {
                selectSelectiveEle.addElement(new TextElement("'" + introspectedTable.getSelectByExampleQueryId() + "' as QUERYID,"));
            }

            if (!selectOne) {
                // issues#20
                XmlElement ifDistinctElement = new XmlElement("if");
                ifDistinctElement.addAttribute(new Attribute("test", "example.distinct"));
                ifDistinctElement.addElement(new TextElement("distinct"));
                selectSelectiveEle.addElement(ifDistinctElement);
            }
        } else {
            selectSelectiveEle.addElement(new TextElement("select"));
            if (stringHasValue(introspectedTable.getSelectByPrimaryKeyQueryId())) {
                selectSelectiveEle.addElement(new TextElement("'" + introspectedTable.getSelectByPrimaryKeyQueryId() + "' as QUERYID,"));
            }
        }

        selectSelectiveEle.addElement(this.generateSelectiveElement(introspectedTable));
        selectSelectiveEle.addElement(new TextElement("from " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()));

        if (byExample) {
            selectSelectiveEle.addElement(XmlElementGeneratorTools.getUpdateByExampleIncludeElement(introspectedTable));

            XmlElement ifElement1 = new XmlElement("if");
            ifElement1.addAttribute(new Attribute("test", "example.orderByClause != null"));
            ifElement1.addElement(new TextElement("order by ${example.orderByClause}"));
            selectSelectiveEle.addElement(ifElement1);
        } else {
            boolean and = false;
            StringBuffer sb = new StringBuffer();
            for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
                sb.setLength(0);
                if (and) {
                    sb.append("  and ");
                } else {
                    sb.append("where ");
                    and = true;
                }

                sb.append(MyBatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
                sb.append(" = ");
                sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, introspectedTable.getRules().generatePrimaryKeyClass() ? "record." : null));
                selectSelectiveEle.addElement(new TextElement(sb.toString()));
            }
        }

        if (selectOne) {
            // 只查询一条
            selectSelectiveEle.addElement(new TextElement("limit 1"));
        }

        return selectSelectiveEle;
    }
生成selectOneByExampleSelective
@param introspectedTable
@return