Implementation of Mybatis in query

Source: Internet
Author: User

Wu's view, the problem is very simple, but when Baidu came out of the results let people disappointed.

Baidu's results are divided into 2 types

1. If only one parameter is passed, a list or array can be used, which is a better understanding

2. If you pass multiple parameters, you can only use a map to contain multiple parameters, that is not to say I was uploaded to the service layer of the Pojo object, but also to transform into a map to use, so it is not smart ...

Baidu a half-day, found all is an article wandering, so two kinds of statements, MyBatis official documents on the issue is not mentioned.

So I wrote a junit test case and tried it with a try attitude.

Mapper File:

<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 and Service.java don't mention it.

Write the use case directly inside JUnit:

@Test      Public void testmybatisinquery ()    {        new  projectvo ();                ListNew 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 ());        }    }

Try it, it's ready ....

  

Implementation of Mybatis in query

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.