zoukankan      html  css  js  c++  java
  • mybatis传递多个参数值(转)

    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()); 
     
      }
  • 相关阅读:
    无法为该请求检索数据。 (Microsoft.SqlServer.Management.Sdk.Sfc)
    java.net.NoRouteToHostException: No route to host
    Microsoft SQL Server,错误: 1807
    System.Data.SqlClient.SqlError: 该数据库是在运行版本 8.00.0194 的服务器上备份
    jfinal 日志log4j使用
    遇见未来系列专访 | 聆听时代最前沿的声音
    Html5新增元素中Canvas 与内联SVG的比较
    Raphael JS
    Raphael.js简易教程
    jfinal--乱码问题
  • 原文地址:https://www.cnblogs.com/aigeileshei/p/5871127.html
Copyright © 2011-2022 走看看