4862610
4862610

Reputation: 325

how to make mybatis insert uncertain table and columns

what I want is just like

 insert into  #{tableName} (#{tableColumn1}, ...) values (#{value1}, ... )

in mapper.xml

if I but it went wrong even through I set

statementType="STATEMENT"

how can I make it ?

Upvotes: 1

Views: 761

Answers (1)

4862610
4862610

Reputation: 325

Well I've get the key,

when using #{} it'll be "prepared" if you want use dynamic table name and table columns u need use ${}

e.g

    INSERT INTO
        ${tableName}
    <foreach collection="columns" item="column" open="(" close=")" separator=",">
        ${column} 
    </foreach>          
        VALUES
    <foreach collection="values" item="value"  open="(" close=")" separator=",">
        '${value}'
    </foreach>

If anyone have same question I hope it'll be useful!

Upvotes: 1

Related Questions