• [转shasiqq]@Param 注解在Mybatis中的使用 以及传递参数的三种方式


    第一种:

    Dao层的方法

    [java] view plain copy
     
    1. <span style="font-size:12px;">Public User selectUser(String name,String password);</span>  

    对应的Mapper.xml

    [html] view plain copy
     
    1. <select id="selectUser" resultMap="BaseResultMap">  
    2.     select  *  from user_user_t   where user_name = #{0} and user_password=#{1}  
    3. </select>  


    第二种:

    该方法采用Map传多参数

    Dao层的方法

    [java] view plain copy
     
    1. <span style="font-size:12px;">Public User selectUser(Map paramMap);</span>  

    对应的Mapper.xml

    [html] view plain copy
     
    1. <span style="font-size:12px;"><select id=" selectUser" resultMap="BaseResultMap">  
    2.    select  *  from user_user_t   where user_name = #{userName,jdbcType=VARCHAR} and user_password=#{userPassword,jdbcType=VARCHAR}  
    3. </select></span>  

    Service层调用

    [java] view plain copy
     
    1. <span style="font-size:12px;">public User xxxSelectUser(){  
    2. Map paramMap=new hashMap();  
    3. paramMap.put(“userName”,”对应具体的参数值”);  
    4. paramMap.put(“userPassword”,”对应具体的参数值”);  
    5. User user=xxx. selectUser(paramMap);}</span>  

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

    第三种:

    Dao层的方法

    [java] view plain copy
     
    1. <span style="font-size:12px;">Public User selectUser(@param(“userName”)Stringname,@param(“userpassword”)String password);</span>  

    对应的Mapper.xml

    [html] view plain copy
     
    1. <span style="font-size:12px;"><select id=" selectUser" resultMap="BaseResultMap">  
    2.    select  *  from user_user_t   where user_name = #{userName,jdbcType=VARCHAR} and user_password=#{userPassword,jdbcType=VARCHAR}  
    3. </select></span>  

    Ps:如果要传对象请参考---》http://blog.csdn.net/shasiqq/article/details/51222077

  • 相关阅读:
    HDU2795Biliboard
    Choose and Divide UVa10375 题解
    NKOJ2322: OSU!
    Git学习笔记(0)
    NKOJ2317 英语四六级考试
    NKOJ2321 东方project
    NKOJ2319 奇怪的班级 题解
    两点之间最短路径:弗洛伊德算法
    poj2524 Ubiquitous Religions
    SAP&nbsp;PA&nbsp;共享&nbsp;免费下载
  • 原文地址:https://www.cnblogs.com/rexienk/p/9044353.html
Copyright © 2020-2023  润新知