使用ibatis进行查询,我想查询一个字段有多个值得时候的结果,sql语句是这样的
select*fromeadepteawhereea.deptidin('001008','001009','001010','001007')...
select * from eadept ea where ea.deptid in ('001008','001009','001010','001007')
展开
展开全部
从你的dao层传值过来。因为是多个变量,所以要用map传。
ibatis配置文件中写:
select * from eadept ea where ea.deptid in (#id1#,#id2#,#id3#,#id4#)。
dao层里面用map封装:
map.put("id1","001008");
map.put("id2","001009");
map.put("id3","001010");
map.put("id4","001007");
然后把map传过去就行。试试把!希望对你有帮助!
ibatis配置文件中写:
select * from eadept ea where ea.deptid in (#id1#,#id2#,#id3#,#id4#)。
dao层里面用map封装:
map.put("id1","001008");
map.put("id2","001009");
map.put("id3","001010");
map.put("id4","001007");
然后把map传过去就行。试试把!希望对你有帮助!
2013-04-28
展开全部
官网的文档有说明的。
<select id="dynamicForeachTest" resultType="Blog">
select * from t_blog where id in
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
public void dynamicForeachTest() {
SqlSession session = Util.getSqlSessionFactory().openSession();
BlogMapper blogMapper = session.getMapper(BlogMapper.class);
List<Integer> ids = new ArrayList<Integer>();
ids.add(1);
ids.add(3);
ids.add(6);
List<Blog> blogs = blogMapper.dynamicForeachTest(ids);
for (Blog blog : blogs)
System.out.println(blog);
session.close();
}
如果不行,换MyBatis
<select id="dynamicForeachTest" resultType="Blog">
select * from t_blog where id in
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
public void dynamicForeachTest() {
SqlSession session = Util.getSqlSessionFactory().openSession();
BlogMapper blogMapper = session.getMapper(BlogMapper.class);
List<Integer> ids = new ArrayList<Integer>();
ids.add(1);
ids.add(3);
ids.add(6);
List<Blog> blogs = blogMapper.dynamicForeachTest(ids);
for (Blog blog : blogs)
System.out.println(blog);
session.close();
}
如果不行,换MyBatis
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询