ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

mybatis配置文件foreach等应用

2021-01-09 17:30:21  阅读:236  来源: 互联网

标签:配置文件 discount items price spec item foreach mybatis id


<select id="queryItemComments" parameterType="Map" resultType="com.imooc.pojo.vo.ItemCommentVO">
    SELECT
        ic.comment_level as commentLevel,
        ic.content as content,
        ic.sepc_name as specName,
        ic.created_time as createdTime,
        u.face as userFace,
        u.nickname as nickname
    FROM
        items_comments ic
    LEFT JOIN
        users u
    ON
        ic.user_id = u.id
    WHERE
        ic.item_id = #{paramsMap.itemId}
        <if test="paramsMap.level!=null and paramsMap.level!=''">
          and ic.comment_level = #{paramsMap.level}
        </if>
 </select>
<select id="searchItems" parameterType="Map" resultType="com.imooc.pojo.vo.SearchItemsVO">
    SELECT
    i.id as itemId,
    i.item_name as itemName,
    i.sell_counts as sellCounts,
    ii.url as imgUrl,
    tempSpec.price_discount as price
    FROM
    items i
    LEFT JOIN
    items_img ii
    on
    i.id = ii.item_id
    LEFT JOIN
    (SELECT item_id,MIN(price_discount) as price_discount from items_spec GROUP BY item_id) tempSpec
    on
    i.id = tempSpec.item_id
    WHERE
    ii.is_main = 1
    <if test="paramsMap.keywords!=null and paramsMap.keywords!=''">
        and i.item_name like '%${paramsMap.keywords}%'
    </if>
    order by
    <choose>
        <when test="paramsMap.sort == &quot;c&quot; ">
            i.sell_counts desc
        </when>
        <when test="paramsMap.sort == &quot;p&quot; ">
            tempSpec.price_discount asc
        </when>
        <otherwise>
            i.item_name asc
        </otherwise>
    </choose>
</select>
    <!-- k: 默认,代表默认排序,根据name-->
    <!-- c: 根据销量排序-->
    <!-- p: 根据价格排序-->
<select id="searchItemsByThirdCat" parameterType="Map" resultType="com.imooc.pojo.vo.SearchItemsVO">
    SELECT
    i.id as itemId,
    i.item_name as itemName,
    i.sell_counts as sellCounts,
    ii.url as imgUrl,
    tempSpec.price_discount as price
    FROM
    items i
    LEFT JOIN
    items_img ii
    on
    i.id = ii.item_id
    LEFT JOIN
    (SELECT item_id,MIN(price_discount) as price_discount from items_spec GROUP BY item_id) tempSpec
    on
    i.id = tempSpec.item_id
    WHERE
    ii.is_main = 1
    and i.cat_id = #{paramsMap.catId}

    order by
    <choose>
        <when test="paramsMap.sort == &quot;c&quot; ">
            i.sell_counts desc
        </when>
        <when test="paramsMap.sort == &quot;p&quot; ">
            tempSpec.price_discount asc
        </when>
        <otherwise>
            i.item_name asc
        </otherwise>
    </choose>
</select>
    <select id="queryItemsBySpecIds" parameterType="List" resultType="com.imooc.pojo.vo.ShopcartVO">
        SELECT
        t_items.id as itemId,
        t_items.item_name as itemName,
        t_items_img.url as itemImgUrl,
        t_items_spec.id as specId,
        t_items_spec.`name` as specName,
        t_items_spec.price_discount as priceDiscount,
        t_items_spec.price_normal as priceNormal
        FROM
        items_spec t_items_spec
        LEFT JOIN
        items t_items
        ON
        t_items.id = t_items_spec.item_id
        LEFT JOIN
        items_img t_items_img
        on
        t_items_img.item_id = t_items.id
        WHERE
        t_items_img.is_main = 1
        AND
        t_items_spec.id IN
        <foreach collection="paramsList" index="index" item="specId" open="(" separator="," close=")">
            #{specId}
        </foreach>
    </select>

标签:配置文件,discount,items,price,spec,item,foreach,mybatis,id
来源: https://blog.csdn.net/qingwenc/article/details/112394628

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有