閱讀301 返回首頁    go 阿裏雲 go 技術社區[雲棲]


Mybatis傳遞多個參數

 

ibatis3如何傳遞多個參數有兩個方法:一種是使用java.Map,另一種是使用JavaBean。

 

通過Map傳遞多個參數 

parameterType 可以是別名或完全限定名,map或者java.util.Map,這兩個都是可以的
       
<select 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 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());        
}

 

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

 

 

 

最後更新:2017-04-03 05:40:22

  上一篇:go Oracle日期顯示問題以及trunc方法的使用
  下一篇:go java反射3——類實例的方法1