Mybatis传递多个参数

 

ibatis3如何传递多个参数有两个方法:一种是使用Map,另一种是使用JavaBean。

  

<!-- 
 
  使用HashMap传递多个参数  
 
 parameterType 可以是别名或完全限定名 ,map->java.util.Map,这两个都是可以的 
 
 --> 
 
 <selectid="selectBlogByMap"parameterType="map"resultType="Blog"
 
     SELECT t.ID, t.title, t.content 
 
       FROM blog t 
 
      WHERE t.title = #{h_title} 
 
        AND t.content =#{h_content} 
 
 </select> 
 
 <!-- 使用JavaBean传递多个参数 --> 
 
 <selectid="selectBlogByBean"parameterType="Blog"resultType="Blog"
 
     SELECT t.ID, t.title, t.content 
 
       FROM blog t 
 
      WHERE t.title = #{title} 
 
        AND t.content =#{content} 
 
 </select>
/**
 
   * 通过Map传递多个参数
 
   */ 
 
  @Test 
 
  public void testSelectByMap() { 
 
      SqlSession session = sqlSessionFactory.openSession(); 
 
      Map<String, Object> param=new HashMap<String, Object>(); 
 
      param.put("h_title", "oracle"); 
 
      param.put("h_content", "使用序列!"); 
 
      Blog blog = (Blog)session.selectOne("cn.enjoylife.BlogMapper.selectBlogByMap",param); 
 
      session.close(); 
 
      System.out.println("blog title:"+blog.getTitle()); 
 
  
 
  /**
 
   * 通过JavaBean传递多个参数
 
   */ 
 
  @Test 
 
  public void testSelectByBean() { 
 
      SqlSession session = sqlSessionFactory.openSession(); 
 
      Blog blog=new Blog(); 
 
      blog.setTitle("oracle"); 
 
      blog.setContent("使用序列!"); 
 
      Blog newBlog = (Blog)session.selectOne("cn.enjoylife.BlogMapper.selectBlogByBean",blog); 
 
      session.close(); 
 
      System.out.println("new Blog ID:"+newBlog.getId()); 
 
  }

mybatis传递多个参数值(转)的更多相关文章

  1. mybatis 传递参数的方法总结

    有三种mybatis传递参数的方式: 第一种 mybatis传入参数是有序号的,可以直接用序号取得参数 User selectUser(String name,String area); 可以在xml ...

  2. MyBatis传递参数

    MyBatis传递参数 一.使用 map 接口传递参数 在 MyBatis 中允许 map 接口通过键值对传递多个参数,把接口方法定义为 : public List<Role> findR ...

  3. Mybatis传递多个参数的4种方式(干货)

    Mybatis传递多个参数的4种方式(干货)-----https://blog.csdn.net/youanyyou/article/details/79406486

  4. Mybatis传递多个参数的几种方式

    顺序传参法 public User selectUser(String name, int deptId); <select id="selectUser" resultMa ...

  5. mybatis传递参数到mapping.xml

    第一种方案 ,通过序号传递 DAO层的函数方法 Public User selectUser(String name,String area); 对应的Mapper.xml <select id ...

  6. Mybatis 传递多个参数

    Mybatis提供了4种传递多个参数的方法: 1 Map sql语句 接口 调用方法 这个方法虽然简单易用,但是存在一个弊端:Map存储的元素是键值对,可读性不好. 2 注解 使用MyBatis的参数 ...

  7. Mybatis传递List集合

    完整错误如下: org.apache.ibatis.binding.BindingException: Parameter ‘customerIdList’ not found. Available ...

  8. Mybatis传递多个参数

    方法一: //DAO层的函数方法Public User selectUser(String name,String area); 对应的Mapper.xml <select id="s ...

  9. Mybatis传递多个参数的解决办法(三种)

    第一种方案 DAO层的函数方法 Public User selectUser(String name,String area); 对应的Mapper.xml <select id="s ...

随机推荐

  1. 【Python】切片

    处理Python的部分元素,称之为切片. 创建切片 指定要是用的第一个元素和最后一个元素的索引,与range()函数一样,Python在到达你指定的第二个索引前面的元素后停止. 先定义一个列表vege ...

  2. EasyUI这个框架用了好久了,总结一下遇到的问题和解决方法

    1. jQuery EasyUI动态添加控件或者ajax加载页面后不能自动渲染问题的解决方法: 我们之所以在页面中,只要书写相应easyui的class,Easyui就能成功渲染页面,这是因为解析器在 ...

  3. PM2.5

    http://baike.baidu.com/view/1423678.htm PM2.5是指大气中直径小于或等于2.5微米的颗粒物,也称为可入肺颗粒物.虽然PM2.5只是地球大气成分中含量很少的组分 ...

  4. Android微信分享功能实例+demo

    Android微信分享功能实例 1 微信开放平台注册 2 获得appId,添加到程序中,并运行程序 3 使用应用签名apk生成签名,添加到微信开放平台应用签名,完成注册 4 测试分享功能. 有问题请留 ...

  5. hdu4857 &amp; BestCoder Round #1 逃生(拓扑逆排序+优先队列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=4857 ----------------------------------------------- ...

  6. HTML5 2D平台游戏开发#3冲刺

    断断续续地把Demo又写了一阵,终于把角色的冲刺动作完成了.冲刺的作用是使角色能够快速移动,闪避攻击或障碍.其完成效果如下: 首先,仍需要一些变量来表示角色的冲刺状态: //标识角色是否处于冲刺中 v ...

  7. vsftpd 自动安装脚本

    #!/usr/bin/env python # -*- coding: utf-8 -*- __author__ = 'cpy' import os import re import sys impo ...

  8. mongodb的启动参数--quiet

    ”mongo群友在群里问了个问题,问的是--quiet启动参数如何用的? 如何理解安静的输出?“ 看到这个问题,之前看过--quiet这个参数,没有认真研究过,也没在生产中使用过. 在mongodb启 ...

  9. CPI

    CPI (Consumer Price Index 物价指数) 是政府用来衡量通货膨胀的其中一个数据.通俗的讲,CPI就是市场上的货物价格增长百分比.一般市场经济国家认为CPI在2-3%属于可接受范围 ...

  10. 苹果开发之COCOA编程(第三版)上半部分

    第一章:什么是Cocoa 1.1 历史简介 1.2 开发工具:Xcode.Interface Builder(一个GUI构建工具).在它们内部,使用gcc为编译器来编译代码,并使用gdb来查找错误 1 ...