如果把logIds当做字符串传进来,则会报如下错误:

UPDATE 	hs_search_log SET is_collect = #{status}  WHERE id IN(#{logIds}) AND user_id=#{user_id}

报错:### Cause: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: ‘3,4,5’

以数组或者集合的方式传参,然后遍历就可以解决以上问题

    <update id="updateCollectStatus">
        UPDATE 	hs_search_log SET is_collect = #{status}  WHERE   user_id=#{user_id} AND id IN
        <foreach collection="logIds" index="index" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </update>

对应sql语句

UPDATE hs_search_log SET is_collect = ? WHERE user_id=? AND id IN ( ? , ? , ? )

发表评论

邮箱地址不会被公开。 必填项已用*标注