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 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)