Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 在foreach中使用MyBatis更新_Sql_Oracle_Mybatis - Fatal编程技术网

Sql 在foreach中使用MyBatis更新

Sql 在foreach中使用MyBatis更新,sql,oracle,mybatis,Sql,Oracle,Mybatis,我正在为MyBatis中的更新语句而挣扎。我想将多个字符串放在一行中: UPDATE MY_FILTERS SET GROUPS = <foreach item="item" collection="selectedGroups" open="" separator="," close=""> #{item} </foreach>, TEMPLATES = <foreach item="item" collection="selectedTem

我正在为MyBatis中的更新语句而挣扎。我想将多个字符串放在一行中:

UPDATE MY_FILTERS
SET
GROUPS =
  <foreach item="item" collection="selectedGroups" open="" separator="," close="">
    #{item}
  </foreach>,
TEMPLATES = 
  <foreach item="item" collection="selectedTemplates" open="" separator="," close="">
    #{item}
  </foreach>
where ID = #{id}

但仍然会出现这样的例外情况:

org.springframework.jdbc.BadSqlGrammarException: 
### Error updating database. Cause: java.sql.SQLException: ORA-01747: invalid user.table.column, table.column, or column specification 
### The error may involve my.mybatis.PRPMapper.saveParamsToDB-Inline 
### The error occurred while setting parameters 
### SQL: UPDATE MY_FILTERS SET GROUPS = ? , ? , TEMPLATES = ? , ? where ID = ? 
### Cause: java.sql.SQLException: ORA-01747: invalid user.table.column, table.column, or column specification ; bad SQL grammar []; nested exception is java.sql.SQLException: ORA-01747: invalid user.table.column, table.column, or column specification javax.faces.event.AbortProcessingException: org.springframework.jdbc.BadSqlGrammarException: 
试一试

open = "'" close = "'"


使用这些设置,mybatis不绑定变量,而是执行字符串替换。请注意,字符串替换容易受到sql注入的攻击。如果您还面临一些问题,请发布mystatis构建的更新sql查询

谢谢您的回复。我得到:
org.springframework.jdbc.InvalidResultSetAccessException:###更新数据库时出错。原因:java.sql.SQLException:无效列索引####该错误可能涉及my.mybatis.PRPMapper.saveParamsToDB-Inline####设置参数时出错####sql:更新我的过滤器集组='?','?',模板=“?”其中ID=?####原因:java.sql.SQLException:列索引无效;对SQL[]的ResultSet访问无效;嵌套异常是java.sql.SQLException:无效列索引javax.faces.event.AbortProcessingException:…
@Andrej:你说得对,我错过了单引号转义;我更新了回复。您是否也使用了${item}?谢谢,首先是我的错误,我没有使用
$
。最后,它使用
open=“””分隔符=“”,“close=“””
org.springframework.jdbc.BadSqlGrammarException: 
### Error updating database. Cause: java.sql.SQLException: ORA-01747: invalid user.table.column, table.column, or column specification 
### The error may involve my.mybatis.PRPMapper.saveParamsToDB-Inline 
### The error occurred while setting parameters 
### SQL: UPDATE MY_FILTERS SET GROUPS = ? , ? , TEMPLATES = ? , ? where ID = ? 
### Cause: java.sql.SQLException: ORA-01747: invalid user.table.column, table.column, or column specification ; bad SQL grammar []; nested exception is java.sql.SQLException: ORA-01747: invalid user.table.column, table.column, or column specification javax.faces.event.AbortProcessingException: org.springframework.jdbc.BadSqlGrammarException: 
open = "'" close = "'"
separator = ","  
${item}