欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

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

时间:2021-03-24 10:29:22|栏目:JAVA代码|点击:

方案一

  Dao层的函数方法

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

  对应的Mapper.xml

 <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 

 <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层调用

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

 <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> 

上一篇:简单了解如何在spring中使用RabbitMQ

栏    目:JAVA代码

下一篇:解决java调用dll报Unable to load library错误的问题

本文标题:Mybatis传递多个参数的三种实现方法

本文地址:http://www.codeinn.net/misctech/86934.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有