我将参数设置成 bizCode="'BIZ-NATIONAL-SOUTUDI','BIZ-NATIONAL-DEFUALT'";
在ibatis里面<select id="queryListTblBcsShare" parameterType="com.ums.bcs.front.model.Share" resultMap="ShareResultMap">
select BIZ_ID,
BIZ_CODE,
DETAIL_ID,
IS_CUS_URL,
BIZ_CLIENT_VERSION,
BIZ_STATUS,
SHARE_URL,
SHARE_TYPE
from TBL_BCS_SHARE
where (BIZ_CODE in (${bizCode} $)
and SHARE_TYPE=#{shareType,jdbcType=VARCHAR})
or (BIZ_CODE is null
and SHARE_TYPE=#{shareType,jdbcType=VARCHAR})
or(BIZ_CODE=#{bizCode,jdbcType=VARCHAR}
and SHARE_TYPE is null)
or(BIZ_CODE is null and SHARE_TYPE is null)
order by BIZ_CODE nulls last,SHARE_TYPE nulls last
</select>
然后在控制台报错:
BIZ_CODE,
DETAIL_ID,
IS_CUS_URL,
BIZ_CLIENT_VERSION,
BIZ_STATUS,
SHARE_URL,
SHARE_TYPE
from TBL_BCS_SHARE
where (BIZ_CODE in ('BIZ-NATIONAL-SOUTUDI','BIZ-NATIONAL-DEFUALT' $)
and SHARE_TYPE=?)
or (BIZ_CODE is null
and SHARE_TYPE=?)
or(BIZ_CODE=?
and SHARE_TYPE is null)
or(BIZ_CODE is null and SHARE_TYPE is null)
order by BIZ_CODE nulls last,SHARE_TYPE nulls last
17:44:32.706 INFO [bio-8080-exec-3] c.h.c.m.i.p.DiclectStatementHandlerInterceptor - ----pra:com.ums.bcs.front.model.Share@bc3ed6
17:44:32.706 INFO [bio-8080-exec-3] c.h.c.m.i.p.DiclectStatementHandlerInterceptor - ---------------------------------------------------------
17:44:32.846 INFO [bio-8080-exec-3] o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
17:44:32.906 INFO [bio-8080-exec-3] o.s.j.support.SQLErrorCodesFactory - SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
org.springframework.jdbc.BadSqlGrammarException:
### Error querying database. Cause: java.sql.SQLException: ORA-00911: 无效字符
如果用 select BIZ_ID,
BIZ_CODE,
DETAIL_ID,
IS_CUS_URL,
BIZ_CLIENT_VERSION,
BIZ_STATUS,
SHARE_URL,
SHARE_TYPE
from TBL_BCS_SHARE
where (BIZ_CODE in (${bizCode})
and SHARE_TYPE=#{shareType,jdbcType=VARCHAR})
or (BIZ_CODE is null
and SHARE_TYPE=#{shareType,jdbcType=VARCHAR})
or(BIZ_CODE=#{bizCode,jdbcType=VARCHAR}
and SHARE_TYPE is null)
or(BIZ_CODE is null and SHARE_TYPE is null)
order by BIZ_CODE nulls last,SHARE_TYPE nulls last
这样就只有一个值了,
在控制台输出:
BIZ_CODE,
DETAIL_ID,
IS_CUS_URL,
BIZ_CLIENT_VERSION,
BIZ_STATUS,
SHARE_URL,
SHARE_TYPE
from TBL_BCS_SHARE
where (BIZ_CODE in (BIZ-NATIONAL-SOUTUDI)
and SHARE_TYPE=?)
or (BIZ_CODE is null
and SHARE_TYPE=?)
or(BIZ_CODE=?
and SHARE_TYPE is null)
or(BIZ_CODE is null and SHARE_TYPE is null)
order by BIZ_CODE nulls last,SHARE_TYPE nulls last
17:47:13.774 INFO [bio-8080-exec-3] c.h.c.m.i.p.DiclectStatementHandlerInterceptor - ----pra:com.ums.bcs.front.model.Share@129efd0
17:47:13.774 INFO [bio-8080-exec-3] c.h.c.m.i.p.DiclectStatementHandlerInterceptor - ---------------------------------------------------------
17:47:13.824 INFO [bio-8080-exec-3] o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
17:47:13.885 INFO [bio-8080-exec-3] o.s.j.support.SQLErrorCodesFactory - SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
org.springframework.jdbc.BadSqlGrammarException:
### Error querying database. Cause: java.sql.SQLException: ORA-00904: "SOUTUDI": 标识符无效
### The error may involve com.ums.bcs.front.dao.ShareDao.queryListTblBcsShare-Inline
### The error occurred while setting parameters
### Cause: java.sql.SQLException: ORA-00904: "SOUTUDI": 标识符无效
应该怎么写啊?求大神指教
------解决思路----------------------
为什么不用#{aaa}
------解决思路----------------------
在参数外面加上""试试,比如说BIZ_CODE in ("${bizCode} $")
------解决思路----------------------
'${aaa}' 加单引号
------解决思路----------------------
实在不行就用foreach吧
------解决思路----------------------
直接 in ( $xxx$ ) 可以吧。我以前项目就这么做。
------解决思路----------------------
foreach用#{}不要用${}。
------解决思路----------------------
用$肯定可以的,ibatis根本不会修改你传入的值,只可能是你传值出错
------解决思路----------------------
from TBL_BCS_SHARE
where (BIZ_CODE in ('BIZ-NATIONAL-SOUTUDI','BIZ-NATIONAL-DEFUALT' $)
and SHARE_TYPE=?)
多有个$号, 后面的$号不要 改成 where (BIZ_CODE in ('BIZ-NATIONAL-SOUTUDI','BIZ-NATIONAL-DEFUALT' )