码迷,mamicode.com
首页 > 数据库 > 详细

Mybatis查询实例,sql中的in在Mybatis中怎么写--以list为查询条件

时间:2016-06-27 12:13:08      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

在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>
在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>

Mybatis查询实例,sql中的in在Mybatis中怎么写--以list为查询条件

标签:

原文地址:http://www.cnblogs.com/lonely-buffoon/p/5619460.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!