qq_38081432 2020-04-19 16:47 采纳率: 100%
浏览 1143
已结题

mybatis批量更新,foreach标签问题

图片说明
mapper里面代码,用的foreach标签

        <foreach collection="list" item="item"  open="(" close=")" separator=";">
            update delivery
            <set> state = "2"</set>
             <where> id = ${item}</where>
        </foreach>

报错

图片说明

图片说明

org.springframework.jdbc.BadSqlGrammarException: 
### Error updating database.  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 delivery
             SET state = "2" 
              WHERE id = 22 
     ' at line 2
### The error may involve com.bishe.dao.CompanyHandller.updateState-Inline
### The error occurred while setting parameters
### SQL: (               update delivery              SET state = "2"                WHERE id = 22           )
### 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 delivery
             SET state = "2" 
              WHERE id = 22 
     ' at line 2
; bad SQL grammar []; nested exception is 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 delivery
             SET state = "2" 
              WHERE id = 22 
     ' at line 2
  • 写回答

3条回答 默认 最新

  • SXGY_07 2020-04-19 19:45
    关注

    不要括号

    <foreach collection="list" item="item"  open="" close=";" separator=";">
    
    评论

报告相同问题?