在使用Mybatis的時候,經常會有各種各樣的參數傳遞,不同類型,不同個數的參數。
先上個例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
public List<LifetouchRelease> findOfficeList( @Param ( "lifetouchRelease" ) LifetouchRelease lifetouchRelease, @Param ( "advertisementId" ) String advertisementId, @Param ( "officeName" ) String officeName, @Param ( "isOnline" ) Integer isOnline); <select id= "findOfficeList" resultType= "LifetouchRelease" > SELECT <include refid= "lifetouchReleaseColumns" /> FROM lifetouch_release a <include refid= "lifetouchReleaseJoins" /> <where> < if test= "lifetouchRelease.typeIdentification > 0" > AND a.type_identification = #{lifetouchRelease.typeIdentification} </ if > < if test= "lifetouchRelease.category != null andlifetouchRelease.category.id != null and lifetouchRelease.category.id != ''" > AND a.release_type_id = #{lifetouchRelease.category.id} </ if > AND a.office_id is not null AND a.advertisement_id like '%${advertisementId}%' AND (select name from sys_office where id=a.office_id) like '%${officeName}%' < if test= "isOnline != null" > AND a.del_flag = #{isOnline} </ if > </where> <choose> <when test= "lifetouchRelease.page !=null andlifetouchRelease.page.orderBy != null and lifetouchRelease.page.orderBy != ''" > ORDER BY ${lifetouchRelease.page.orderBy} </when> <otherwise> ORDER BY a.update_date DESC </otherwise> </choose> </select> |
上面是一個包含:實體對象,普通類型,多個參數的傳遞。
多個參數:使用注解的方式實現
實體對象:實體對象跟普通類型參數傳遞方法一樣,只是在用的時候,以 對象名.(點)對象屬性名 的方式調用就可以了。
其它傳遞,不過數據類型多復雜也是如此。
以上所述是小編給大家介紹的Mybatis多參數及實體對象傳遞實例講解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
原文鏈接:http://blog.csdn.net/molashaonian/article/details/53860295