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. pom.xml基础配置

    pom.xml基础配置: maven中,最让我迷惑的还是那一堆配置! 就拿这个属性配置来说: 我需要让整个项目统一字符集编码,就需要设定 <project.build.sourceEncodin ...

  2. HDU 5042 GCD pair 预处理+二分 分段

    点击打开链接 #include <stdio.h> #include <string.h> #include <iostream> #include <cma ...

  3. Rom Modified [Galaxy 3 Tested]

    1,Virtualbox虚拟机设置-数据空间注意这里不要勾选那个自动挂载,不然后面mount总会提示mount.vbox.. invalid argument. 2,进入ubuntu中,在终端下输入 ...

  4. 转 FreeBSD 安装JDK

    cd /usr/ports/java/openjdk6make install clean 默认什么都不用选,因为我们配置的是运行环境, 中间编译过程好久... 偷懒的干脆就直接安装/usr/port ...

  5. 字符串== equals

    经常碰到比较字符串的题, eg: public class StringDemo{ private static final String MESSAGE = "taobao"; ...

  6. Hibernate学习五----------组件属性

    © 版权声明:本文为博主原创文章,转载请注明出处 实例 1.项目结构 2.pom.xml <project xmlns="http://maven.apache.org/POM/4.0 ...

  7. XXE攻击

    1.背景 现在很多应用都存在XXE(XML External Entity attack)漏洞,就是xml外部实体攻击,比如facebook,很多XML的解析器默认是含有XXE漏洞的. 2.xml的定 ...

  8. Hollis原创|不了解这12个语法糖,别说你会Java

    GitHub 2.5k Star 的Java工程师成神之路 ,不来了解一下吗? GitHub 2.5k Star 的Java工程师成神之路 ,真的不来了解一下吗? GitHub 2.5k Star 的 ...

  9. 不安装Oracle客户端也能使用PL/SQL

    解压缩 instantclient_12_1 到 D:\Oracle\instantclient_12_1 在文件夹内建立目录, /NETWORK/ADMIN 在该目录下,新建文件tnsnames.o ...

  10. 使用mysqld_multi 实现Mysql 5.6.36 + 5.7.18 单机多实例多版本安装

    Mysql 5.6.36 + 5.7.18 单机多实例多版本安装 随着硬件层面的发展,各种高性能服务器如雨后春笋般出现,但高性能服务器不免造成浪费, MySQL单机多实例,是指在一台物理服务器上运行多 ...