当前位置:首页 > mybatis > 正文内容

Mybatis传递多个参数的三种实现方法

关中浪子5年前 (2021-03-21)mybatis2197
买泛域名SSL证书 送5斤装现摘猕猴桃一箱、同时提供技开源商城搭建免费技术支持。
泛域名ssl证书 239元1年送1个月、单域名39元1年,Sectigo(原Comodo证书)全球可信证书,强大的兼容性,高度安全性,如有问题7天内可退、可开发票
加微信VX 18718058521 备注SSL证书
【腾讯云】2核2G4M云服务器新老同享99元/年,续费同价

方案一

  Dao层的函数方法

   1 Public User selectUser(String name,String area);

  对应的Mapper.xml

1
2
3
<select id=" selectUser" resultMap="BaseResultMap">
  select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}
</select>

其中,#{0}代表接收的是dao层中的第一个参数,#{1}代表dao层中第二参数,更多参数一致往后加即可。

方案二(Map传值)

  Dao层的函数方法

   1 Public User selectUser(Map paramMap);

  对应的Mapper.xml 

1
2
3
<select id=" selectUser" parameterType="map" resultMap="BaseResultMap">
  select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}
</select>

Service层调用

1
2
3
4
5
6
Private User xxxSelectUser(){
  Map paramMap = new hashMap();
  paramMap.put(“userName”,”对应具体的参数值”);
  paramMap.put(“userArea”,”对应具体的参数值”);
  User user=xxx. selectUser(paramMap);
}

方案三(推荐)

  Dao层的函数方法

   1 Public User selectUser(@Param(“userName”) String name,@Param(“userArea”) String area);

  对应的Mapper.xml

1
2
3
<select id=" selectUser" parameterType="map" resultMap="BaseResultMap">
  select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}
</select>


找梯子最重要的就是稳定,这个已经上线三年了,一直稳定没有被封过,赶紧下载备用吧!

扫描二维码推送至手机访问。

版权声明:本文由码农翻生发布,如需转载请注明出处。

本文链接:https://lubojian.cn/post/27.html

分享给朋友:
返回列表

没有更早的文章了...

下一篇:mybatis框架学习(完整)强烈推荐

相关文章

MyBatis源码分析 SqlSession.getMapper()背后做了什么

一、什么是 MyBatis?       直接看官方文档:https://mybatis.org/mybatis-3/zh/index.html。       ...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。