Mybatis查询实例,sql中的in在Mybatis中怎么写
1个回答
展开全部
在service中把参数放到袜侍HashMap中
List<String> list = new ArrayList<String>();
list.add("x");
list.add("y");
list.add("前嫌z");
String s = "A"
Date d = new Date();
HashMap<String,Object> param = new HashMap<String,Object>();
param.put("list",list);
param.put("s"慧好手,s);
param.put("d",d);
XXXDao.queryXXX(param);
在Mybatis的Mapper中是这么写:
<select id = "queryXXX",resultType = "XXX", paramterType = "java.lang.HashMap">
select * from tab where zi_duan1 = #{s} and zi_duan2 = #{d}
and zi_duan3 in
<foreach item="item" index="index" collection="list" open="("
separator="," close=")">
#{item}
</foreach>
</select>
List<String> list = new ArrayList<String>();
list.add("x");
list.add("y");
list.add("前嫌z");
String s = "A"
Date d = new Date();
HashMap<String,Object> param = new HashMap<String,Object>();
param.put("list",list);
param.put("s"慧好手,s);
param.put("d",d);
XXXDao.queryXXX(param);
在Mybatis的Mapper中是这么写:
<select id = "queryXXX",resultType = "XXX", paramterType = "java.lang.HashMap">
select * from tab where zi_duan1 = #{s} and zi_duan2 = #{d}
and zi_duan3 in
<foreach item="item" index="index" collection="list" open="("
separator="," close=")">
#{item}
</foreach>
</select>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询