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