Linhai- 2017-06-05 02:01 采纳率: 0%
浏览 1303

mybatis在三表连表查询时如何通过存储过程获取数据

****进公司不久,因为要完成百万级的数据量查询 ,以前没有接触过这方面,在mybatis中
用自己书写的动态sql查询的话查询量在10w时效率就很低,求大神知道如果通过存储过程进
行查询。一共三张表,需要实现多条件动态查询以及分页,下面是自己写的sql,求告知存储过程如何实现:所有的查询条件都封装在pojo---CollectDataQuery里面

select c.id cid,c.score,c.publishDate,c.author,c.title,c.content,c.source,c.url,c.source,c.click,c.zanTotal,
c.repeatTotal,c.forward,c.type,t.key_words,t.id tId
from t_collectdata c
left JOIN t_data_subject d on d.id=c.id
left JOIN t_task t on d.subjectId=t.id

order by ${publishDate} ${order}
limit #{pageNum},#{pageSize}

    <sql id="whereSql">
    <where>
        <if test="null!=ids and ids.size>0">
            AND d.subjectId IN
            <foreach collection="ids" item="item" index="index" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <choose>
            <when test="keyWords!=null and keyWords !=''">
                and (c.title like concat('%',#{keyWords},'%')
                or c.content like concat('%',#{keyWords},'%'))
            </when>

            <when test="title!=null and title!=''">
                and c.title like concat('%',#{title},'%')
            </when>
            <when test="content!=null and content!=''">
                and c.content like concat('%',#{content},'%')
            </when>
        </choose>

        <if test="type!=null and type!=''">
            AND c.type = #{type}
        </if>

        <if test="score!=null and score!=''">
            <choose>
                <when test="score==2">
                    AND c.score BETWEEN #{i} and #{j}
                </when>
                <when test="score==-1">
                    <![CDATA[ and (c.score<#{i})]]>
                </when>
                <when test="score==1">
                    <![CDATA[ and (c.score>#{j})]]>
                </when>
            </choose>
        </if>

        <if test="startTime!=null and score!=''">
            AND c.publishDate BETWEEN #{startTime} and #{endTime}
        </if>

        <if test="taskId!=null and taskId!=''">
            AND t.id = #{taskId}
        </if>
    </where>
</sql>

    其中t_data_subject是t_collectdata和t_task的中jian表

    下面时两张表的字段对应
    <resultMap id="CollectDataMap" type="com.bicap.cloud.monitor.entity.CollectData">
    <id column="cid" property="id"/>
    <result column="score" property="score"/>
    <result column="publishDate" property="publishDate"/>
    <result column="author" property="author"/>
    <result column="authorId" property="authorId"/>
    <result column="content" property="content"/>
    <result column="source" property="source"/>
    <result column="url" property="url"/>
    <result column="title" property="title"/>
    <result column="source" property="source"/>
    <result column="click" property="click"/>
    <result column="zanTotal" property="zanTotal"/>
    <result column="repeatTotal" property="repeatTotal"/>
    <result column="forward" property="forward"/>
    <result column="type" property="type"/>
    <collection property="keyWords" resultMap="keywordsMap"/>
</resultMap>

<resultMap id="keywordsMap" type="com.bicap.cloud.monitor.entity.Task">
    <id property="id" column="tId"/>
    <result property="keyWords" column="key_words"/>
</resultMap>

    急求大腿知道用存储过程如何实现
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 急matlab编程仿真二阶震荡系统
    • ¥20 TEC-9的数据通路实验
    • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
    • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
    • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
    • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
    • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
    • ¥15 python爬取bilibili校园招聘网站
    • ¥30 求解达问题(有红包)
    • ¥15 请解包一个pak文件