zoukankan      html  css  js  c++  java
  • Mybatis传递多个参数

    一、使用索引?#{index}

    DAO层函数方法

    Public User selectUser(String name, String area);
    

      Mapper.xml中SQL

    <select id="selectUser" resultMap="BaseResultMap">
        select  
            *  
        from 
            user_user_t
        where 
            user_name = #{0} and user_area=#{1}
    </select>
    

      

    二、使用Map

    DAO层函数方法

    Public User selectUser(Map<String, Object> map);
    

      Mapper.xml中SQL

    <select id="selectUser" resultMap="BaseResultMap">
        select  
            *  
        from 
            user_user_t
        where 
        user_name = #{username, jdbcType=VARCHAR} 
        and user_area = #{userarea, jdbcType=VARCHAR}
    </select>
    

      Service层函数调用

    public User selectUser() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("username", "zhangsan");
        map.put("userarea", "beijing");
        User user = mapper.selectUser(map); 
    }
    

      

    三、使用注解

    DAO层函数

    public User selectUser(@Param("userName")String username, @Param("userArea")String userarea);
    

      Mapper.xml中SQL

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

      

  • 相关阅读:
    数据攻略●R语言自述
    测试实例
    xml反射
    过滤器
    使用s标签来进行简单的表格配置
    将Spring、Hibernate、Struts2连接起来
    Spring容器
    初见Spring框架
    Spring框架的AOP
    Hibernate里面的几个方法
  • 原文地址:https://www.cnblogs.com/wqsbk/p/10555139.html
Copyright © 2011-2022 走看看