mybatis 传递多个参数 --解决mybatis查询使用多个参数方法--javabean传统方法和map方法

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

  •   
  •     <select id="selectBlogByBean" parameterType="Blog" resultType="Blog">  
  •         SELECT t.ID, t.title, t.content  
  •           FROM blog t  
  •          WHERE t.title = #{title}  
  •            AND t.content =#{content}  
  •     select> 
    1.   
    2.     @Test  
    3.     public void testSelectByMap() {  
    4.         SqlSession session = sqlSessionFactory.openSession();  
    5.         Map param=new HashMap();  
    6.         param.put("h_title""oracle");  
    7.         param.put("h_content""使用序列!");  
    8.         Blog blog = (Blog)session.selectOne("cn.enjoylife.BlogMapper.selectBlogByMap",param);  
    9.         session.close();  
    10.         System.out.println("blog title:"+blog.getTitle());  
    11.     }  
    12.       
    13.     @Test  
    14.     public void testSelectByBean() {  
    15.         SqlSession session = sqlSessionFactory.openSession();  
    16.         Blog blog=new Blog();  
    17.         blog.setTitle("oracle");  
    18.         blog.setContent("使用序列!");  
    19.         Blog newBlog = (Blog)session.selectOne("cn.enjoylife.BlogMapper.selectBlogByBean",blog);  
    20.         session.close();  
    21.         System.out.println("new Blog ID:"+newBlog.getId());  

你可能感兴趣的:(Mybatis,Exception)