简体   繁体   English

通过将参数传递给MyBatis无法获得结果

[英]Cannot get the result by passing the parameter to MyBatis

I have a select SQL in MyBatis like this: 我在MyBatis有一个选择SQL ,如下所示:

SELECT * FROM MYTABLE WHERE id IN (#{ids})

The parameter ids I passed in is correct, which I can get while I'm debugging. 我传入的参数ids是正确的,可以在调试时获取。 And also, I can run this SQL in MySQL with the parameter correctly and get the results. 而且,我可以在MySQL使用参数正确运行此SQL并获取结果。

But nothing is gotten running with Java code. 但是,使用Java代码无法运行任何东西。

I printed the SQL of MyBatis and the SQL is like this: 我打印了SQLMyBatisSQL是这样的:

SELECT * FROM MYTABLE WHERE id IN (?)

and the parameters shown in log is correct too( '1', '2', '3' ). 并且log中显示的参数也正确( '1', '2', '3' )。

Why can't I get the data by code? 为什么不能通过代码获取数据?

I'd be appreciated if anyone can help. 如果有人可以帮助,我将不胜感激。

You need to use <foreach> as described in the documentation . 您需要按照文档中的说明使用<foreach>

See this other SO question if you are using annotations. 如果您使用注解, 请参阅另一个SO问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM