首页 > 其他 > 详细

Mybatis一对多分页查询 条数不对

时间:2020-03-16 10:08:44      阅读:134      评论:0      收藏:0      [点我收藏+]

查询文章列表用到了一对多

 <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>

  

Mybatis一对多分页查询 条数不对

原文:https://www.cnblogs.com/song1024/p/12501758.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!