SELECT a.smid,a.smx,a.smy,a.NAME FROM BusPoint a , BusPointline b
WHERE a.StopID = b.BusPointID AND a.smid in (133,132);
在mybatis框架中,上面的sql语句如何编写?
在mybatis框架中,sql中in是怎么用的?
那位大神知道~~~
导读: select * from txt1 select * from txt2 select * from txt1 where name in (select name from txt2 where chk = 0) select * from txt1 where name not in (select name from txt2 where chk = 0) select * fro......
答案就在这里:Sql语句中IN等方面的用法
----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。
SQL中怎么写,MyBatis 的mapper.xml就怎么写。两者是没有区别的。
你问的应该是in中的值是变量的情况下要怎么写吧。可以参考下面的
List<BusPoint > selectByIn(List<Integer> smids)
xml
select * from BusPoint where smid in
<select id="selectByIn"
<foreach collection="smids" item="smid" index="index" open="(" separator="," close=")">
#{smid}
</foreach>
</select>
SQL中怎么写,MyBatis 的mapper.xml就怎么写。两者是没有区别的。
你问的应该是in中的值是变量的情况下要怎么写吧。可以参考下面的
···
List selectByIn(List smids)
xml
select * from BusPoint where smid in
#{smid}
···
有两种方式:
第一种为楼上所写,将in中的参数以数组或集合方式传入,xml中的select 用foreach
第二种:参数为字符串,List selectByIn(String ids);
xml
SELECT a.smid,a.smx,a.smy,a.NAME FROM BusPoint a , BusPointline b
WHERE a.StopID = b.BusPointID AND a.smid in (${ids});
注:$没有防sql注册
我遇到的问题是当参数拼成字符串进去后,只会返回字符串中第一个逗号前的数据,让我很惊讶