mybatis映射系列教程7:columnPrefix 的用法
当一个collection 定义了一个columnPrefix时,其含义是将前缀自动添加到它下面的column中,如下所示:
- <resultMap id="blogResult" type="Blog">
- <id property="id" column="blog_id" />
- <result property="title" column="blog_title"/>
- <collection property="posts" ofType="Post" resultMap="blogPostResult" columnPrefix="post_"/>
- </resultMap>
-
- <resultMap id="blogPostResult" type="Post">
- <id property="id" column="id"/> <!--在collection中则表示为:post_id-->
- <result property="subject" column="subject"/> <!--在collection中则表示为:post_subject-->
- <result property="body" column="body"/> <!--在collection中则表示为:post_body-->
- </resultMap>
等价于:
- <resultMap id="blogResult" type="Blog">
- <id property="id" column="blog_id" />
- <result property="title" column="blog_title"/>
- <collection property="posts" ofType="Post">
- <id property="id" column="post_id"/>
- <result property="subject" column="post_subject"/>
- <result property="body" column="post_body"/>
- </collection>
- </resultMap>