查询文章列表用到了一对多
<resultMap id="articleResultMap" type="com.hq.advert.web.article.vo.ArticleMappingVo">
<id column="article_id" property="articleId"/>
<result column="article_title" property="articleTitle"/>
<result property="articleAuther" column="article_auther"/>
<result property="articleContent" column="article_content"/>
<result property="articleCreateTime" column="article_create_time"/>
<result property="articleDealerId" column="article_dealer_id"/>
<result property="articleLalbel" column="article_lalbel"/>
<result property="articleIssueTime" column="article_issue_time"/>
<result property="articlePageViews" column="article_page_views"/>
<result property="articleStatus" column="article_status"/>
<result property="articleModifyTime" column="article_modify_time"/>
<result property="articleChannelPageViews" column="article_channel_page_views"/>
<association property="businessVo" column="article_id"
javaType="com.hq.advert.web.article.vo.ArticleBusinessMappingVo"
select="com.hq.advert.mapper.BusinessArticleMapper.selectByArticleId"
>
</association>
<collection property="channelVo" ofType="com.hq.advert.web.article.vo.ArticleChannelMappingVo"
column="articleId">
<id property="id" column="id"/>
<result property="channelId" column="channel_id"/>
<result property="channelPageViews" column="channel_page_views"/>
<association property="articleChannelVo" column="channel_id"
javaType="com.hq.advert.web.article.vo.ArticleChannelChangnelMappingVo"
select="com.hq.advert.mapper.ChannelVoMapper.selectChannelById"/>
</collection>
</resultMap>
一对多代码这样写会导致分页后数量对不上
<collection property="channelVo" ofType="com.hq.advert.web.article.vo.ArticleChannelMappingVo"
column="articleId">
<id property="id" column="id"/>
<result property="channelId" column="channel_id"/>
<result property="channelPageViews" column="channel_page_views"/>
<association property="articleChannelVo" column="channel_id"
javaType="com.hq.advert.web.article.vo.ArticleChannelChangnelMappingVo"
select="com.hq.advert.mapper.ChannelVoMapper.selectChannelById"/>
</collection>
解决办法
<resultMap id="articleResultMap" type="com.hq.advert.web.article.vo.ArticleMappingVo">
<id column="article_id" property="articleId"/>
<result column="article_title" property="articleTitle"/>
<result property="articleAuther" column="article_auther"/>
<result property="articleContent" column="article_content"/>
<result property="articleCreateTime" column="article_create_time"/>
<result property="articleDealerId" column="article_dealer_id"/>
<result property="articleLalbel" column="article_lalbel"/>
<result property="articleIssueTime" column="article_issue_time"/>
<result property="articlePageViews" column="article_page_views"/>
<result property="articleStatus" column="article_status"/>
<result property="articleModifyTime" column="article_modify_time"/>
<result property="articleChannelPageViews" column="article_channel_page_views"/>
<association property="businessVo" column="article_id"
javaType="com.hq.advert.web.article.vo.ArticleBusinessMappingVo"
select="com.hq.advert.mapper.BusinessArticleMapper.selectByArticleId"
>
</association>
<collection property="channelVo" ofType="com.hq.advert.web.article.vo.ArticleChannelMappingVo"
column="article_id" select="com.hq.advert.mapper.ArticleChannelMapper.selectArticleChannelList" />
</resultMap>
