RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
mybatis映射XML文件的示例分析

这篇文章主要介绍mybatis映射XML文件的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

成都创新互联公司长期为上1000+客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为金城江企业提供专业的网站设计制作、成都网站设计金城江网站改版等技术服务。拥有10年丰富建站经验和众多成功案例,为您定制开发。

mybatis映射XML文件

一个简单的映射文件:




当然这个文件中没有任何的元素

The Mapper XML files have only a few first class elements :

  1. cache – Configuration of the cache for a given namespace.

  2. cache-ref – Reference to a cache configuration from another namespace.

  3. resultMap – The most complicated and powerful element that describes how to load your objects from the database result sets.

  4. sql – A reusable chunk of SQL that can be referenced by other statements.

  5. insert – A mapped INSERT statement.

  6. update – A mapped UPDATE statement.

  7. delete – A mapped DELETE statement.

  8. select – A mapped SELECT statement.

select

简单的例子:


 SELECT * FROM PERSON WHERE ID = #{id}

select也有很多属性可以让你配置:

Result Maps

官网给了个最最复杂的例子

大体意思呢就是一个博客系统有一个作者,很多博文,博文中有一个作者,很多评论,很多标签(包括了一对多,一对一)



 select
    B.id as blog_id,
    B.title as blog_title,
    B.author_id as blog_author_id,
    A.id as author_id,
    A.username as author_username,
    A.password as author_password,
    A.email as author_email,
    A.bio as author_bio,
    A.favourite_section as author_favourite_section,
    P.id as post_id,
    P.blog_id as post_blog_id,
    P.author_id as post_author_id,
    P.created_on as post_created_on,
    P.section as post_section,
    P.subject as post_subject,
    P.draft as draft,
    P.body as post_body,
    C.id as comment_id,
    C.post_id as comment_post_id,
    C.name as comment_name,
    C.comment as comment_text,
    T.id as tag_id,
    T.name as tag_name
 from Blog B
    left outer join Author A on B.author_id = A.id
    left outer join Post P on B.id = P.blog_id
    left outer join Comment C on P.id = C.post_id
    left outer join Post_Tag PT on PT.post_id = P.id
    left outer join Tag T on PT.tag_id = T.id
 where B.id = #{id}




 
  
 
 
 
  
  
  
  
  
  
 
 
  
  
  
  
   
  
  
   
  
  
   
  
 

以上是“mybatis映射XML文件的示例分析”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!


本文名称:mybatis映射XML文件的示例分析
URL分享:http://sczitong.cn/article/gggggi.html