动态sql_可以应用的场景

<!--查商品-->
<select id="selectProductByCategoryId" resultMap="ProductVOMap2">
select
product_id,
product_name,
category_id,
root_category_id,
sold_num,
product_status,
content,
create_time,
update_time
from product
where category_id = #{cid}
limit #{start}, #{limit}
</select>
<!-- 根据关键字 模糊查询 -->
<select id="selectProductByKeyword" resultMap="ProductVOMap2">
select
product_id,
product_name,
category_id,
root_category_id,
sold_num,
product_status,
content,
create_time,
update_time
from product
where product_name like "{kw}"
limit #{start}, #{limit}
</select>
本文展示了如何使用动态SQL进行商品查询,包括按类别ID精确查询和按关键字模糊查询。示例中演示了如何利用MyBatis的动态SQL片段来构造SQL语句,实现分页限制,并对产品信息进行筛选。动态SQL在数据库操作中提供了灵活性和效率,适用于多条件、动态条件的查询场景。
109

被折叠的 条评论
为什么被折叠?



