MySql语法报错org.springframework.jdbc.BadSqlGrammarException:


<update id="updateCustomerStateByIds" >
    update
         t_customer
    set
         state = 1
    where
         id
    in
    <foreach collection="list" item="item" open="(" close=")" separator=",">
      #{item}
    </foreach>
  </update>

img

不都打印出来了,SQL语法错误,list为空导致 in 后面没有 ()

你这是批量更新呀,这样写试试

<update id="updateCustomerStateByIds" >
    update
         t_customer
    set
         state = 1
    where
         id
    in
(
    <foreach collection="list" item="item" open="" index="index" close="" separator=",">
      #{item}
    </foreach>
)
  </update>

要注意的是你要保证你的list不是对象集合,而是数字集合,否则报错,如果是对象集合,#{item}要改成#{item.id}之类的

看报错里面的sql语句,in后面根本就没有参数