• 分页关联查询时 出现查出数据和条数不匹配 级联查询


    商品表   图片表

    <resultMap id="BaseResultMap" type="com.shop.domain.admin.ShopItem" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="item_coding" property="itemCoding" jdbcType="VARCHAR" />
    <result column="item_name" property="itemName" jdbcType="VARCHAR" />
    <result column="item_name_second" property="itemNameSecond" jdbcType="VARCHAR" />
    <result column="item_type" property="itemType" jdbcType="VARCHAR" />
    <result column="warehouse" property="warehouse" jdbcType="VARCHAR" />
    <result column="price" property="price" jdbcType="DOUBLE" />
    <result column="brand" property="brand" jdbcType="VARCHAR" />
    <result column="item_status" property="itemStatus" jdbcType="VARCHAR" />
    <result column="delivery_info" property="deliveryInfo" jdbcType="VARCHAR" />
    <result column="sales_service" property="salesService" jdbcType="VARCHAR" />
    <result column="product_note" property="productNote" jdbcType="VARCHAR" />
    <result column="item_cat_id" property="itemCatId" jdbcType="INTEGER" />
    <result column="item_cat_name" property="itemCatName" jdbcType="VARCHAR" />
    <result column="barcode" property="barcode" jdbcType="VARCHAR" />
    <result column="item_state" property="itemState" jdbcType="VARCHAR" />
    <result column="creat_time" property="creatTime" jdbcType="VARCHAR" />
    <result column="update_time" property="updateTime" jdbcType="VARCHAR" />
    </resultMap>

    <resultMap id="BaseResultMap"
    type="com.shop.domain.admin.ShopImage">
    <result column="id" property="id" jdbcType="VARCHAR" />
    <result column="pid" property="pid" jdbcType="INTEGER" />
    <result column="pid_second" property="pidSecond"
    jdbcType="VARCHAR" />
    <result column="image_address" property="imageAddress"
    jdbcType="VARCHAR" />
    <result column="creat_time" property="creatTime"
    jdbcType="VARCHAR" />
    </resultMap>

    <sql id="base_sql" >
    id, item_coding, item_name, item_name_second, item_type, price, warehouse, brand,
    item_status, delivery_info, sales_service, product_note, item_cat_id, item_cat_name,
    barcode, item_state, creat_time, update_time ,id as sss
    </sql>

    <!-- 级联查询 -->
    <resultMap id="BaseResultMapCascade" type="com.shop.domain.admin.ShopItem" extends="BaseResultMap">
    <collection property="imageInfo" javaType="java.util.List" ofType="com.shop.domain.admin.ShopImage" select="com.shop.dao.admin.ShopImageMapper.selectImageBypiidSecond" column="{pidSecond=sss}">
    </collection>
    </resultMap>

    <!-- 查询商品详情图片 -->
    <select id="selectImageBypiidSecond" parameterType="map"
    resultMap="BaseResultMap">
    select
    <include refid="base_sql"></include>
    from shop_image
    where pid_second = #{pidSecond}
    </select>

    <!-- 分页查询商品信息 -->
    <select id="selectCommodityInfo" parameterType="map" resultMap="BaseResultMapCascade">
    select <include refid="base_sql"></include> from 
    shop_item
    where 1=1 
    <if test="wheres != null">
    ${wheres}
    </if>
    GROUP BY id
    order by creat_time
    <if test="page !=null and number != null and number !=''">
    limit #{page},#{number}
    </if>
    </select>

  • 相关阅读:
    python并发编程之gevent协程(四)
    python并发编程之asyncio协程(三)
    python并发编程之multiprocessing进程(二)
    python并发编程之threading线程(一)
    python设计模式之内置装饰器使用(四)
    python设计模式之装饰器详解(三)
    python设计模式之迭代器与生成器详解(五)
    EF code First数据迁移学习笔记
    15.02.13-代码小技巧
    Route学习笔记之Area的Route注册
  • 原文地址:https://www.cnblogs.com/cw828/p/11660600.html
Copyright © 2020-2023  润新知