Methods for passing multiple parameters (multiple parameters)

Source: Internet
Author: User
Tags cdata
When querying with MyBatis, you usually pass multiple parameters, in general, there are two solutions in this case:
1, use HashMap to do.
2, using MyBatis's own multiple parameter transfer mode to do. Add the following separately:

Passing multiple parameters with HashMap
For example, there are the following statements:
Program code
<select id= "selectbydate" parametertype= "map" resultmap= "Campaignstats" >
<! [cdata[
Select * from Campaignstats Where statsdate >= #{start} and Statsdate <= #{end}
]]>
</select>

The corresponding Java code is
Program code
Public list<dpcampaignstats> selectbydate (date start, date end) {
sqlsession session = Sqlsessionfactory.opensession ();
try {
map<string, date> map = new hashmap<string, date> ();
Map.put ("Start", start);
Map.put ("End", end);
list<dpcampaignstats> list = session.selectlist ("dpcampaignstats.selectbydate", map);
return list;
} finally {
Session.close ();
}
}

It's just the first way, and of course there are the following methods

MyBatis multiple parameter passing methods.
The same statement
Program code
<select id= "Selectbydate" resultmap= "Campaignstats" >
<! [cdata[
Select * from Campaignstats Where statsdate >= #{param1} and Statsdate <= #{param2}
]]>
</select>

Please note that there is no parametertype at this time, but similar parameters like #{param1} are used. The same Java code also needs to be changed
Program code
Public list<dpcampaignstats> selectbydate (date start, date end) {
sqlsession session = Sqlsessionfactory.opensession ();
try {
list<dpcampaignstats> list = session.selectlist ("Dpcampaignstats.selectbydate", start,end);
return list;
} finally {
Session.close ();
}

}



From:http://www.yihaomen.com/article/java/426.htm

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.