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

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

    通过Map传递多个参数 

    parameterType 可以是别名或完全限定名,map或者java.util.Map,这两个都是可以的
            
    <select id="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>        

      
    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传递多个参数
         
    <select id="selectBlogByBean" parameterType="Blog" resultType="Blog">
     select t.ID, t.title, t.content
     from blog t
     wheret.title = #{title}
     and t.content =#{content}         
    </select>

       
    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());         
    }

    原帖地址:http://kb.cnblogs.com/a/2291110/

  • 相关阅读:
    微信公众号-框架业务
    微信公众号-加解密数据demo坑
    JS进制转换,浮点数相加,数字判断
    lamp环境-编译安装
    批量解压目录下的文件
    设置用户sudo -s拥有root权限
    CentOS 6.5-默认没开启网络连接:开启网络连接
    检查一下是否安装了环境,安装则卸载
    负载均衡-多台机子session不起效:把php.ini中file改为memcache存储
    由json生成php配置文件
  • 原文地址:https://www.cnblogs.com/handsome1013/p/4994600.html
Copyright © 2011-2022 走看看