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 @   任国强  阅读(206)  评论(0编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
点击右上角即可分享
微信分享提示