private XmlElement replacePrimaryKeyXmlElement(IntrospectedTable introspectedTable, XmlElement element, String id, boolean update) {
        XmlElement withVersionEle = XmlElementTools.clone(element);

        XmlElementTools.replaceAttribute(withVersionEle, new Attribute("id", id));
        XmlElementTools.replaceAttribute(withVersionEle, new Attribute("parameterType", "map"));

        FormatTools.replaceComment(commentGenerator, withVersionEle);

        // 替换查询语句
        Iterator<Element> elementIterator = withVersionEle.getElements().iterator();
        boolean flag = false;
        while (elementIterator.hasNext()) {
            Element ele = elementIterator.next();
            if (ele instanceof TextElement && ((TextElement) ele).getContent().matches(".*where.*")) {
                flag = true;
            }

            if (flag) {
                elementIterator.remove();
            }
        }

        // where 语句
        withVersionEle.addElement(new TextElement("where " + this.generateVersionEleStr()));
        if (introspectedTable.getPrimaryKeyColumns().size() == 1) {
            IntrospectedColumn introspectedColumn = introspectedTable.getPrimaryKeyColumns().get(0);
            StringBuilder sb = new StringBuilder();
            sb.append("  and ");
            sb.append(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
            sb.append(" = ");
            if (update) {
                sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "record."));
            } else {
                sb.append("#{key,jdbcType=");
                sb.append(introspectedColumn.getJdbcTypeName());
                if (StringUtility.stringHasValue(introspectedColumn.getTypeHandler())) {
                    sb.append(",typeHandler=");
                    sb.append(introspectedColumn.getTypeHandler());
                }
                sb.append("}");
            }
            withVersionEle.addElement(new TextElement(sb.toString()));
        } else {
            for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
                StringBuilder sb = new StringBuilder();
                sb.append("  and ");
                sb.append(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
                sb.append(" = ");
                sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, update ? "record." : "key."));
                withVersionEle.addElement(new TextElement(sb.toString()));
            }
        }

        return withVersionEle;
    }
private XmlElement replacePrimaryKeyXmlElement(IntrospectedTable introspectedTable, XmlElement element, String id, boolean update) {
        XmlElement withVersionEle = XmlElementTools.clone(element);

        XmlElementTools.replaceAttribute(withVersionEle, new Attribute("id", id));
        XmlElementTools.replaceAttribute(withVersionEle, new Attribute("parameterType", "map"));

        FormatTools.replaceComment(commentGenerator, withVersionEle);

        
        Iterator<Element> elementIterator = withVersionEle.getElements().iterator();
        boolean flag = false;
        while (elementIterator.hasNext()) {
            Element ele = elementIterator.next();
            if (ele instanceof TextElement && ((TextElement) ele).getContent().matches(".*where.*")) {
                flag = true;
            }

            if (flag) {
                elementIterator.remove();
            }
        }

        
        withVersionEle.addElement(new TextElement("where " + this.generateVersionEleStr()));
        if (introspectedTable.getPrimaryKeyColumns().size() == 1) {
            IntrospectedColumn introspectedColumn = introspectedTable.getPrimaryKeyColumns().get(0);
            StringBuilder sb = new StringBuilder();
            sb.append("  and ");
            sb.append(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
            sb.append(" = ");
            if (update) {
                sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "record."));
            } else {
                sb.append("#{key,jdbcType=");
                sb.append(introspectedColumn.getJdbcTypeName());
                if (StringUtility.stringHasValue(introspectedColumn.getTypeHandler())) {
                    sb.append(",typeHandler=");
                    sb.append(introspectedColumn.getTypeHandler());
                }
                sb.append("}");
            }
            withVersionEle.addElement(new TextElement(sb.toString()));
        } else {
            for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
                StringBuilder sb = new StringBuilder();
                sb.append("  and ");
                sb.append(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
                sb.append(" = ");
                sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, update ? "record." : "key."));
                withVersionEle.addElement(new TextElement(sb.toString()));
            }
        }

        return withVersionEle;
    }
private XmlElement replacePrimaryKeyXmlElement ( IntrospectedTable introspectedTable , XmlElement element , String id , boolean update ) { XmlElement withVersionEle = XmlElementTools . clone ( element ) ; XmlElementTools . replaceAttribute ( withVersionEle , new Attribute ( "id" , id ) ) ; XmlElementTools . replaceAttribute ( withVersionEle , new Attribute ( "parameterType" , "map" ) ) ; FormatTools . replaceComment ( commentGenerator , withVersionEle ) ; // 替换查询语句 Iterator < Element > elementIterator = withVersionEle . getElements ( ) . iterator ( ) ; boolean flag = false ; while ( elementIterator . hasNext ( ) ) { Element ele = elementIterator . next ( ) ; if ( ele instanceof TextElement && ( ( TextElement ) ele ) . getContent ( ) . matches ( ".*where.*" ) ) { flag = true ; } if ( flag ) { elementIterator . remove ( ) ; } } // where 语句 withVersionEle . addElement ( new TextElement ( "where " + this . generateVersionEleStr ( ) ) ) ; if ( introspectedTable . getPrimaryKeyColumns ( ) . size ( ) == 1 ) { IntrospectedColumn introspectedColumn = introspectedTable . getPrimaryKeyColumns ( ) . get ( 0 ) ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( "  and " ) ; sb . append ( MyBatis3FormattingUtilities . getEscapedColumnName ( introspectedColumn ) ) ; sb . append ( " = " ) ; if ( update ) { sb . append ( MyBatis3FormattingUtilities . getParameterClause ( introspectedColumn , "record." ) ) ; } else { sb . append ( "#{key,jdbcType=" ) ; sb . append ( introspectedColumn . getJdbcTypeName ( ) ) ; if ( StringUtility . stringHasValue ( introspectedColumn . getTypeHandler ( ) ) ) { sb . append ( ",typeHandler=" ) ; sb . append ( introspectedColumn . getTypeHandler ( ) ) ; } sb . append ( "}" ) ; } withVersionEle . addElement ( new TextElement ( sb . toString ( ) ) ) ; } else { for ( IntrospectedColumn introspectedColumn : introspectedTable . getPrimaryKeyColumns ( ) ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "  and " ) ; sb . append ( MyBatis3FormattingUtilities . getEscapedColumnName ( introspectedColumn ) ) ; sb . append ( " = " ) ; sb . append ( MyBatis3FormattingUtilities . getParameterClause ( introspectedColumn , update ? "record." : "key." ) ) ; withVersionEle . addElement ( new TextElement ( sb . toString ( ) ) ) ; } } return withVersionEle ; }
替换 主键查询
@param introspectedTable
@param element
@param id
@param update
@return
替换 主键查询