發(fā)現(xiàn)問(wèn)題
在mybatis的動(dòng)態(tài)sql中最常見(jiàn)的錯(cuò)誤就是使用,比如:_frch_item_0 not found
1
|
There is no getter for property named 'states' in 'class com.xingguo.model.User' |
等等。
一般在使用時(shí)出現(xiàn)問(wèn)題是由以下幾種錯(cuò)誤使用方式造成的:
1.參數(shù)類(lèi)型不是List,特別當(dāng)參數(shù)為實(shí)體類(lèi),一個(gè)屬性為list時(shí),注意collection的名字。
2.遍歷時(shí)屬性的名字或者字段錯(cuò)誤
3.多個(gè)參數(shù)時(shí)沒(méi)有使用@param進(jìn)行命名,在sql中順序混亂
下面從MySQL的源碼中看下對(duì)于list參數(shù)是如何解析的。
首先看到DefaultSqlSession.Java中的wrapCollection()
方法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
private Object wrapCollection( final Object object) { if (object instanceof Collection) { StrictMap<Object> map = new StrictMap<Object>(); map.put( "collection" , object); if (object instanceof List) { map.put( "list" , object); } return map; } else if (object != null && object.getClass().isArray()) { StrictMap<Object> map = new StrictMap<Object>(); map.put( "array" , object); return map; } return object; } |
所以從上面可以看到中默認(rèn)情況下寫(xiě)的array和list,也就是collection默認(rèn)的是array和list。
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如有疑問(wèn)大家可以留言交流,謝謝大家對(duì)服務(wù)器之家的支持。
原文鏈接:http://blog.csdn.net/u014231523/article/details/53875560