shop--8.店鋪列表展示--Dao層
阿新 • • 發佈:2018-07-29
return 通過 cat pre 第一個 ltm 取數據 page priority
實現商鋪管理
實現商店列表
實現分頁查詢店鋪,通過條件組合,來篩選出條件範圍內的店鋪列表
分頁查詢中使用LIMIT
第一個參數指定第一個返回記錄行的偏移量,第二個參數指定返回記錄行的最大數目
1 /** 2 * 分頁查詢店鋪,可輸入的條件有:店鋪名(模糊),店鋪狀態,店鋪類別,區域id,owner 3 * @param shopCondition 4 * @param rowIndex 從第幾行開始取數據 5 * @param pageSize 表示返回多少行數據 6 * @param 標簽的作用 取參數的時候需要唯一的標識7 * @return 8 */ 9 List<Shop> queryShopList(@Param("shopCondition")Shop shopCondition, 10 @Param("rowIndex") int rowIndex,@Param("pageSize") int pageSize); 11 /** 12 * 返回queryShopList總數 13 * @param shopCondition 14 * @return 15 */ 16 intqueryShopCount(@Param("shopCondition")Shop shopCondition);
SQL
分頁查詢店鋪信息:可輸入的條件有:店鋪名(模糊查詢),店鋪狀態,店鋪類別,區域Id,owner
使用動態SQL來查
<select id="queryShopList" resultMap="shopMap"> SELECT s.shop_id, s.shop_name, s.shop_desc, s.shop_addr, s.phone, s.shop_img, s.priority, s.create_time, s.last_edit_time, s.enable_status, s.advice, a.area_id, a.area_name, sc.shop_category_id, sc.shop_category_name FROM tb_shop s, tb_area a, tb_shop_category sc<where> <if test="shopCondition.shopCategory!=null and shopCondition.shopCategory.shopCategoryId!=null"> and s.shop_category_id = #{shopCondition.shopCategory.shopCategoryId} </if> <if test="shopCondition.area!=null and shopCondition.shopCategory.areaId!=null"> and shop_area_id = #{shopCondition.area.areaId} </if> <if test="shopCondition.shopName!=null"> and s.shop_name like ‘%${shopCondition.shopName}%‘ </if> <if test="shopCondition.enableStatus!=null"> and s.enable_status = #{shopCondition.status} </if> <if test="shopCondition.owner!=null and shopCondition.owner.userId!=null"> and s.owner_id = #{shopCondition.owner.userId} </if> AND s.area_id = a.area_id AND s.shop_category_id = sc.shop_category_id </where> ORDER BY s.priority DESC LIMIT #{rowIndex},#{pageSize}; </select> <select id="queryShopCount" resultType="int"> SELECT count(1) FROM tb_shop s, tb_area a, tb_shop_category sc <where> <if test="shopCondition.shopCategory!=null and shopCondition.shopCategory.shopCategoryId!=null"> and s.shop_category_id = #{shopCondition.shopCategory.shopCategoryId} </if> <if test="shopCondition.area!=null and shopCondition.shopCategory.areaId!=null"> and shop_area_id = #{shopCondition.area.areaId} </if> <if test="shopCondition.shopName!=null"> and s.shop_name like ‘%${shopCondition.shopName}%‘ </if> <if test="shopCondition.enableStatus!=null"> and s.enable_status = #{shopCondition.status} </if> <if test="shopCondition.owner!=null and shopCondition.owner.userId!=null"> and s.owner_id = #{shopCondition.owner.userId} </if> AND s.area_id = a.area_id AND s.shop_category_id = sc.shop_category_id </where> </select>
shop--8.店鋪列表展示--Dao層