ibatis sql编写问题

lv595604712 2011-04-26 10:43:36
<select id="specialtyCompare" parameterClass="String" resultClass="java.util.HashMap">
select t.def_short_string_04,
t.def_short_string_03,
t.def_short_string_01,
t.def_short_string_02,
x.speciality_name,
x.id,
x.speciality_code,
x.allow_level
from zgw_web_page_data t, xl_speciality x
where t.biz = x.id
and t.biz in (#bizs#);


我传进去的是一个字符串形式的ids,像这样('123','321','125')
报错:
SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException

in那里具体要怎么写?
...全文
63 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
FankieYui 2011-04-26
  • 打赏
  • 举报
回复
#biz:VARCHAR#
这样试试..
游一游走一走 2011-04-26
  • 打赏
  • 举报
回复
如楼上说的以数组或者集合的形式传进去,然后再使用iterate标签进行迭代
还有一种就是使用 $bizs$ 这种形式缺点就是无使用占位符,他会把$bizs$ 直接替换为文字内容
lv595604712 2011-04-26
  • 打赏
  • 举报
回复
知道了,in那里应该用($bizs$),还有sql语句最后不用写分号
  • 打赏
  • 举报
回复
参数是List
parameterClass="java.util.List"
wangjn1982 2011-04-26
  • 打赏
  • 举报
回复
用ibatis的iterate循环

<iterate property="objList[].objList" open="(" close=")" conjunction=",">
#objList[].objList[].target#
</iterate>
  • 打赏
  • 举报
回复
<select id="specialtyCompare" parameterClass="String" resultClass="java.util.HashMap">
select t.def_short_string_04,
t.def_short_string_03,
t.def_short_string_01,
t.def_short_string_02,
x.speciality_name,
x.id,
x.speciality_code,
x.allow_level
from zgw_web_page_data t, xl_speciality x
where t.biz = x.id
<iterate conjunction="," open=" and t.biz in (" close=")">
#[]#
</iterate>

参数已数组传递进去
xifanmax 2011-04-26
  • 打赏
  • 举报
回复
猜测可能出错原因:
传进去的是一个字符串形式的ids,像这样('123','321','125')
在生成sql时是("'123','321','125'"),整个被当成字符串了,望高人解决

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧