Updating SQL db with List – Java and MyBatis

Is it possible to insert a list in MyBatis?

This is the Java code:

@Override
    public void createSubjectPrivileges(final List<SubjectPrivilegesFormDTO> subjectPrivilegesFormDTOList) {
        this.auditingSqlSession.update("createSubjectPrivileges",3,subjectPrivilegesFormDTOList);
    }

What would be the MyBatis code, in case this is possible?

<insert id="createSubjectPrivileges" parameterType="?">
        insert into x (
        a,
        b,
        c
        ) values (
        #{d, jdbcType=NUMERIC},
        #{e, jdbcType=NUMERIC},
        #{f, jdbcType=NUMERIC}
        )
    </insert>

I can always iterate throught the list in Java and insert one each time, but that’s not very good in performance terms, from my point of view.

Thanks in advance.


Source: oop

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.