MyBatis the problem of passing in multiple parameters

Source: Internet
Author: User

One, single parameter:

Public List<xxbean> getxxbeanlist (String xxcode); <select id= "getxxxbeanlist" parametertype= "java.lang.String" resulttype= " Xxbean "> Select t.* from TableName t where t.id= #{id} </select> where the method name and ID are identical, #{} Parameter names and parameters in methods the name has always been, I'm using Xxxbean is a short name, the field list after the select is consistent with the attribute name in the bean, if inconsistent can be supplemented with AS. 

Two, multi-parameter:

Public List<xxxbean> getxxxbeanlist (String xxid, String xxcode);  <ID= "getxxxbeanlist" resulttype= "Xxbean"></Select>  Because it is a multi-parameter then you can not use ParameterType, #{index} is the first number of the index, the index starting from 0         

three, map package multi-parameter:

 public list<  Xxxbean> Getxxxbeanlist (HashMap map); <select id= "Getxxxbeanlist"  Parametertype= "HashMap"  Resulttype= "Xxbean" >  select field ... from XXX where Id=#{xxid} code = #{xxcode} < ;/select> Where HashMap is MyBatis's own configuration of the direct use of the line. The name of key in the map is the one that is used in the #{}, and the map how to encapsulate it is not necessary I said it.  

Iv. List Package in:

Public List<Xxxbean> Getxxxbeanlist (List<String>list);<SelectId= "Getxxxbeanlist"Resulttype= "Xxbean">Select field ... from XXX where ID in<ForeachItem= "Item" index= "Index" collection= "List" open= "(" Separator= ","  Close= ")"> #{item} </foreach> </Select> foreach Last The effect is the Select field ... from the XXX where ID in (' 1 ', ' 2 ', ' 3 ', ' 4 ')          
                                 

five, multi-parameter transmission of the annotated mode is shown:

<id= "getaddrinfo" resultmap= "Com.xxx.xxx.AddrInfo">
Where Addr_id=#{addrid} and Corp_id=#{corpid}</select> Previous in <select> If you want to bring parametertype in the statement, you can not write this now.

Six, SelectList () can only pass one parameter, but the actual required parameter must contain both the string type and the list type when it is processed:

Put the parameters in the map and then take out the list traversal in the map. As follows:

list<string> list_3 = new arraylist<string> ();
New hashmap<string, object>();
List.add ("1");
List.add ("2");
Map2.put ("list", list);//URL ID

Map2.put ("SiteTag", "0");//URL type

Public list<sysweb> Getsysinfo (map<string, object> map2) { return getsqlsession (). SelectList (" Sysweb.getsysinfo ", MAP2);}  

<SelectId= "Getsysinfo"ParameterType= "Java.util.Map"Resulttype= "Sysweb">Select T.syssiteid, T.sitename, t1.mznum as Sitetagnum, t1.mzname as SiteTag, T.url, t.iconpath from Td_web_syssite T left Join Td_mz_mzdy t1 on t1.mznum = T.sitetag and T1.mztype = ten WHERE T.sitetag = #{sitetag} and T.syssiteid not in<foreach collection= "List" Item= "Item" index= "index" Open= "(" close = ")" Separator= ","> #{item} </foreach> </Select  >                   

Source:http://www.cnblogs.com/mingyue1818/p/3714162.html

MyBatis the problem of passing in multiple parameters

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.