Mybatis in 查詢的實現

來源:互聯網
上載者:User

標籤: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 查詢的實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.