第一种:

Dao层的方法

<span style="font-size:12px;">Public User selectUser(String name,String password);</span>  

对应的Mapper.xm

  

<select id="selectUser" resultMap="BaseResultMap">  

    select  *  from user_user_t   where user_name = #{} and user_password=#{}  

  </select>  

第二种:

该方法采用Map传多参数

Dao层的方法

<span style="font-size:12px;">Public User selectUser(Map paramMap);</span>  

对应的Mapper.xml

 <select id=" selectUser" resultMap="BaseResultMap">  
  select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_password=#{userPassword,jdbcType=VARCHAR}
 </select>

Service层调用

public User xxxSelectUser(){  

Map paramMap=new hashMap();  

paramMap.put(“userName”,”对应具体的参数值”);
paramMap.put(“userPassword”,”对应具体的参数值”);
User user=xxx. selectUser(paramMap);}
 

个人认为此方法不够直观,见到接口方法不能直接的知道要传的参数是什么。

第三种:

Dao层的方法

Public User selectUser(@param(“userName”)Stringname,@param(“userpassword”)String password);

对应的Mapper.xml

<select id=" selectUser" resultMap="BaseResultMap">  

   select  *  from user_user_t   where user_name = #{userName,jdbcType=VARCHAR} and user_password=#{userPassword,jdbcType=VARCHAR} 

</select>

第四种:

mapper.java:

public List<User> getUserByParam(User use);

对应Mapper.xml:

<select id="getUserByParam" resultType="com.ray.bean.User" parameterType="com.ray.bean.User" >
select * from t_pub_user t
<where>
<if test="{user_name}!=null">
t.user_name like CONCAT('%',#{user_name},'%')
</if>
<if test="{user_password}!=null">
and t.user_password like CONCAT('%',#{user_password},'%')
</if>
</where>
limit #{},#{}
</select>

@Param注解在mybatis中的使用以及传入参数的几种方式(转)的更多相关文章

  1. @Param注解在Mybatis中的使用 以及传递参数的三种方式

    第一种: Dao层的方法 public User selectUser(String name,String password); 对应的Mapper.xml <select id=" ...

  2. 关于Mybatis中mapper.xml的传入参数简单技巧

    由于在做项目的时候,我看见同事使用的传入参数类型各式各样,感觉没规律可言,闲暇的时候我就自己搭建了项目做了一些传入参数的测试(当然其实更好的方式是看源码,但是博主能力有限,毕竟入行没多久,看起来很吃力 ...

  3. JSP中页面向Action传递参数的几种方式

    <form name="ThisForm" method="POST" action="index.jsp"> form是表单, ...

  4. 关于Mybatis的@Param注解 及 mybatis Mapper中各种传递参数的方法

    原文:https://blog.csdn.net/mrqiang9001/article/details/79520436 关于Mybatis的@Param注解   Mybatis 作为一个轻量级的数 ...

  5. Oracle中函数/过程返回结果集的几种方式

    原文 Oracle中函数/过程返回结果集的几种方式 Oracle中函数/过程返回结果集的几种方式:    以函数return为例,存储过程只需改为out参数即可,在oracle 10g测试通过.    ...

  6. ASP.NET MVC中使用Unity进行依赖注入的三种方式

    在ASP.NET MVC中使用Unity进行依赖注入的三种方式 2013-12-15 21:07 by 小白哥哥, 146 阅读, 0 评论, 收藏, 编辑 在ASP.NET MVC4中,为了在解开C ...

  7. Android中EditText显示明文与密文的两种方式

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 记录输入框显示.隐藏密码的简单布局以及实现方式. 效果图    代码分析 方式一 /**方式一:*/ private void sh ...

  8. shell中调用R语言并传入参数的两种步骤

    shell中调用R语言并传入参数的两种方法 第一种: Rscript myscript.R R脚本的输出 第二种: R CMD BATCH myscript.R # Check the output ...

  9. 在eclipse中使用Maven建web工程的两种方式

    Eclipse版本:Neon Release (4.6.0) Maven版本:3.3.9 第一种方式: 右键新建maven工程,勾选创建一个简单工程 填入信息,注意打包方式要改为war 点击完成,创建 ...

随机推荐

  1. Mvc4_MvcPager 概述

    MvcPager分页控件是在ASP.NET MVC Web应用程序中实现分页功能的一系列扩展方法,该分页控件的最初的实现方法借鉴了网上流行的部分源代码, 尤其是ScottGu的PagedList< ...

  2. Linux下数据库的安装和使用

    数据库有多重要就不用说了,每一个计算机相关行业的人都必须要学会基本的数据库操作,因为你总会用到的. 之前转过一些学习资源: 与MySQL的零距离接触 - 慕课网 Python操作MySQL数据库 生物 ...

  3. const修饰指针

    关于const修饰指针的情况,一般分为如下4种情况: ; const int *a =&b; //情况1 int const *a =&b; //情况2 int* const a =& ...

  4. An unknown server-side error occurred while processing the command.处理

    在调用resetAPP()时,报错:An unknown server-side error occurred while processing the command. 怎么解决呢?请看: 额,Ap ...

  5. 【CodeVS 1038】一元三次方程

    题意 有形如:ax3+bx2+cx+d=0 这样的一个一元三次方程. 给出该方程中各项的系数(a,b,c,d 均为实数),并约定该方程存在三个不同实根(根的范围在-100至100之间),且根与根之差的 ...

  6. Ubuntu 14.04 分区方案

    我磁盘大概还有70多G的空间吧,我全部拿来使用的.真实的双系统哦. 一般来讲,linux系统分区最少要包括/和/swap两个.这样据说会影响性能,没有这样安装过,就无从考证啦.其实就是重装系统的时候, ...

  7. js中event.target,this

    event.target这是注册事件时的对象,或者它的子元素.通常用于比较 event.target 和 this 来确定事件是不是由于冒泡而触发的.经常用于事件冒泡时处理事件委托. 1.this和e ...

  8. GetMemory

    在函数中动态申请内存(虚拟内存,堆),利用指针返回值指向申请的内存.

  9. HDFS使用0

    创建上传文件的:

  10. hdu----(2222)Keywords Search(trie树)

    Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...