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. MFC中几个函数的使用

      1.GetDlgItem() CWnd* GetDlgItem ( int nID ) const;这个就足够了(在MFC中经常这么用),如果你是在win32API下面写的话,那么一般创建一个窗口 ...

  2. Spring学习十四----------Spring AOP实例

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

  3. 2014acm亚洲区域赛陕西赛总结

    这次是第一次出来到外面比赛,一切都是非常新鲜的,带着新鲜来到了古城西安.首先感觉就是志愿者一点都不热情.一副爱理不理的,这不是有违我大西北人的热情好客么. 直接说比赛吧. 第一天热身赛,出了两道非常水 ...

  4. Android_程序未处理异常的捕获与处理

    1.简单介绍 对于程序抛出的未被捕获的异常,可能会导致程序异常退出,界面不友好且应记录关键错误信息上传至server. 这里主要使用UncaughtExceptionHandler 2.代码实现 pu ...

  5. MVC初了解

    MVC:Model-View-Controller,将数据和显示形式分离. Model:能够看做是三层中的D层+B层,实现业务逻辑和与数据库的交互. View:看做是U层,用来显示数据. Contro ...

  6. 分区容量大于16TB的格式化

    File systems do have limits. Thats no surprise. ext3 had a limit at 16 TB file system size. If you n ...

  7. Python学习总结之四 -- 这就是Python的字典

    字典原来是这么回事儿 Python学习到现在,我们已经知道,如果想将值分组到结构中,并且通过编号对其进行引用,列表就可以派上用场.不过,今天,我们将学到一种通过名字引用值的数据结构,应该知道这种数据类 ...

  8. ios - UISearchBar输入框背景色

    //输入框背景色 bar.searchBarStyle = UISearchBarStyleMinimal; [bar positionAdjustmentForSearchBarIcon:UISea ...

  9. 微信小程序设置控件权重

    项目中最常用的两种布局方式,水平布局和垂直布局,在微信小程序中实现起来也比较简单.       1.横向水平布局:         实现水平布局,需要四个view容器组件,其中一个是父容器.如下: & ...

  10. 使用ZipArchive解压

    本文转载至 http://www.apkbus.com/forum.php?mod=viewthread&tid=131390&extra=page%3D1 qqpk360 该用户从未 ...