Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

建议添加batchInsert代码生成 #133

Open
l543227182 opened this issue Apr 16, 2022 · 2 comments
Open

建议添加batchInsert代码生成 #133

l543227182 opened this issue Apr 16, 2022 · 2 comments

Comments

@l543227182
Copy link

建议添加batchInsert代码生成

@moshowgame
Copy link
Owner

亲你好,有没有batchInsert的模板可以share一下,这样可以更好的增加

@lvgongyi
Copy link

lvgongyi commented Jul 31, 2023

mybatis的批量新增生成,供参考,生成的代码可能需自行移除一些无需的字段。
<insert id="batchInsert" parameterType="${packageName}.entity.${classInfo.className}">
    INSERT INTO ${classInfo.originTableName}
    <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
        (
        <#list classInfo.fieldList as fieldItem >
            <#if fieldItem.columnName != "id" >
                ${fieldItem.columnName}<#if fieldItem_has_next>,</#if>
            </#if>
        </#list>
        )
    </#if>
    VALUES
    <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
        <foreach collection="list" index="index" item="item" separator=",">
            (
            <#list classInfo.fieldList as fieldItem >
                <#if fieldItem.columnName != "id" >
                    ${r"#{item."}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,</#if>
                </#if>
            </#list>
            )
        </foreach>
    </#if>
</insert>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants