mybatis 多表联查,支持分页

Mapper

    <select id="queryShopList" resultMap="shopMap">
		SELECT
		shop_id,
		owner_id,
		area_id,
		shop_category_id,
		parent_category_id,
		shop_name,
		shop_desc,
		shop_addr,
		phone,
		shop_img,
		longitude,
		latitude,
		priority,
		create_time,
		last_edit_time,
		enable_status,
		advice
		FROM
		tb_shop
		<where>
			<if test="shopCondition.shopId!=null">
				and shop_id = #{shopCondition.shopId}
			</if>
			<if
				test="shopCondition.shopCategory!=null
				 and shopCondition.shopCategory.shopCategoryId!=null">
				and shop_category_id =
				#{shopCondition.shopCategory.shopCategoryId}
			</if>
			<if
				test="shopCondition.parentCategory!=null
				 and shopCondition.parentCategory.shopCategoryId!=null">
				and parent_category_id =
				#{shopCondition.parentCategory.shopCategoryId}
			</if>
			<if
				test="shopCondition.area!=null
				 and shopCondition.area.areaId!=null">
				and area_id =
				#{shopCondition.area.areaId}
			</if>
			<!-- 写like语句的时候 一般都会写成 like '% %' 在mybatis里面写就是应该是 like '%${name} %' 而不是 
				'%#{name} %' ${name} 是不带单引号的,而#{name} 是带单引号的 -->
			<if test="shopCondition.shopName!=null">
				and shop_name like '%${shopCondition.shopName}%'
			</if>
			<if test="shopCondition.enableStatus!=null">
				and enable_status = #{shopCondition.enableStatus}
			</if>
		</where>
		ORDER BY
		priority DESC
		LIMIT #{rowIndex},#{pageSize};
	</select>
	<select id="queryShopCount" resultType="int">
		SELECT
		count(1)
		FROM
		tb_shop
		<where>
			<if test="shopCondition.shopId!=null">
				and shop_id = #{shopCondition.shopId}
			</if>
			<if
				test="shopCondition.shopCategory!=null
				 and shopCondition.shopCategory.shopCategoryId!=null">
				and shop_category_id =
				#{shopCondition.shopCategory.shopCategoryId}
			</if>
			<if
				test="shopCondition.parentCategory!=null
				 and shopCondition.parentCategory.shopCategoryId!=null">
				and parent_category_id =
				#{shopCondition.parentCategory.shopCategoryId}
			</if>
			<if
				test="shopCondition.area!=null
				 and shopCondition.area.areaId!=null">
				and area_id =
				#{shopCondition.area.areaId}
			</if>
			<!-- 写like语句的时候 一般都会写成 like '% %' 在mybatis里面写就是应该是 like '%${name} %' 而不是 
				'%#{name} %' ${name} 是不带单引号的,而#{name} 是带单引号的 -->
			<if test="shopCondition.shopName!=null">
				and shop_name like '%${shopCondition.shopName}%'
			</if>
			<if test="shopCondition.enableStatus!=null">
				and enable_status = #{shopCondition.enableStatus}
			</if>
		</where>
	</select>


Dao

	/**
	 * 分页查询店铺,可输入的条件有:店铺名(模糊),店铺状态,店铺Id,店铺类别,区域ID
	 * 
	 * @param shopCondition
	 * @param rowIndex
	 * @param pageSize
	 * @return
	 */
	List<Shop> queryShopList(@Param("shopCondition") Shop shopCondition,
			@Param("rowIndex") int rowIndex, @Param("pageSize") int pageSize);

	/**
	 * 返回queryShopList总数
	 * 
	 * @param shopCondition
	 * @return
	 */
	int queryShopCount(@Param("shopCondition") Shop shopCondition);

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值