one to many relation using mybatis or ibatis

前端 未结 1 1946
不知归路
不知归路 2021-01-07 04:12

I have database which has two tables

  post: 
    id
    post_name
    post_desc        

  files:
    file_id
    file_name

  post_attachments
    post_id         


        
相关标签:
1条回答
  • 2021-01-07 04:32

    As shown in the manual, you have to write a more complex query and change the mapper.

    The request will be something like that :

    <select id="selectPosts" resultType="com.mycom.myproject.bean.postBean">  
        select id, post_name, file_id, file_name as postName from post left outer join files
    </select>
    

    And your result map :

    <resultMap id="detailedPostResultMap" type="Blog">
      <result property="id" column="id"/>
      <result property="name" column="post_name"/>
      <collection property=filesAttachment" ofType="FileAttachment">
         <id property="fileId" column="file_id"/>
         <result property="fileName" column="file_name"/>
      </collection>
    </resultMap>
    
    0 讨论(0)
提交回复
热议问题