tableMapper.xml

<update id="updateTables" parameterType="Table">
    <foreach collection="tableList" item="item" separator=";">
        update tb_test
        <trim prefix="SET" suffixOverrides=",">
            <if test="item.name != null">title = #{item.name},</if>
        </trim>
        where id = #{item.id}
    </foreach>
</update>

 

### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update 

检查了sql和单独执行,都没有问题

搜索发现,是出于安全安全,连接数据库不允许使用分号,即不允许一次执行多行sql

解决:

修改数据库连接URL配置添加允许使用分号allowMultiQueries=true

 jdbc:mysql://localhost:3306/test_db?allowMultiQueries=true

备注:

允许使用分号,意味更多的注入风险,校验好用户输入的内容

 

posted on 2025-10-09 23:22  le.li  阅读(13)  评论(0)    收藏  举报