一、Dao层
查询某类商品下的商品
1、shopDao.xml
<select id="queryShopCount" resultType="int">
SELECT
count(*)
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.shopCategory!=null
and shopCondition.shopCategory.parent!=null
and shopCondition.shopCategory.parent.shopCategoryId!=null">
and s.shop_category_id in (select shop_category_id from
tb_shop_category
WHERE parent_id =
#{shopCondition.shopCategory.parent.shopCategoryId})
</if>
<if
test="shopCondition.area!=null and
shopCondition.area.areaId!=null">
and s.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.enableStatus}
</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>
2、数据库
tb_shop
tb_shop_category
3、测试