MyBatis传入多个参数

http://www.cnblogs.com/ningheshutong/p/5828854.html

http://www.2cto.com/database/201409/338155.html

总得来说,单个参数不用说,多个参数不是通过具体的Entity就是通过Map。

Q:能不能用逗号隔开传递parameterType="java.lang.String,java.lang.String"?

A:http://mybatis-user.963551.n3.nabble.com/parameterType-for-multiple-parameters-td3636195.html

More:When you say interface I hope you mean your mapper interface.  If so 
you just need to name your parameters with the @Param annotation. 
This will then place the parameters into a map for you.  You can 
actually just leave off the parameterType attribute it you want.  It 
is not check nor enforced.  I like to use them just to be able to see 
what is coming in.  "map" should still work for you. 

parameterType不是必须出现在XML的语句里的,它既不用来检查什么也不是强制的关键字,完全可以抛弃不写。

要想传两个参数,只需要用@Param修饰一下参数的名字,底层框架就会把他们封装到"map"类型里了(也就是说你都不用自己搞什么new XXMap()的工作)。

本人也用代码验证过了,超过1个参数,必须得用@Param修饰一下(并且得给参数指定一个与在XML中使用时相同的名字)。

posted @ 2016-12-15 11:37  任国强  阅读(205)  评论(0编辑  收藏  举报