標籤:type lis nbsp style div cas cts ram from
兀的一看,這個問題非常的簡單,可是當baidu出來的結果就讓人大失所望了.
baidu的結果分為2種
1.只傳一個參數的話,可以用list或者array,這種比較好理解
2.傳多個參數的話,竟然只能用map來包含多個參數,那不是說我本來傳到service層的pojo對象,還要轉化成map才能用,這樣也太不智能了...
baidu了半天,發現都是一篇文章轉來轉去,就這麼兩種說法,mybatis的官方文檔對這個問題隻字未提.
於是我就抱著試試看的態度寫了個junit的test case嘗試一下.
mapper檔案:
<select id="getTestProjectList" parameterType="com.goldwind.po.ProjectVo" resultType="com.goldwind.po.ProjectExtend"> select * from v_project where id in <foreach item="item" index="index" collection="ids" open="(" separator="," close=")"> #{item} </foreach> </select>
mapper.xml和service.java略過不提
在junit裡面直接寫用例:
@Test public void testMybatisInQuery() { ProjectVo projectVo = new ProjectVo(); List<Integer> ids = new ArrayList<Integer>(); ids.add(1); ids.add(2); projectVo.setIds(ids); List<ProjectExtend> projectList = projectService.getTestProjectList(projectVo); for(ProjectExtend p : projectList) { System.out.println(p.toString()); } }
試了下, 可以了....
Mybatis in 查詢的實現