在mapper.xml文件中如果有多个查询条件是相同的,可以提取处相同部分,封装起来,哪里使用哪里调用
eg:
select * from product where 1=1
and p.productNo like '%${productNo}%'
and p.productName like '%${productName}%'
and o.istatus >= 0
and o.CreateTime >= #{startDate}
and o.CreateTime < #{endDate};
select count(*) from product where 1=1
and p.productNo like '%${productNo}%'
and p.productName like '%${productName}%'
and o.istatus >= 0
and o.CreateTime >= #{startDate}
and o.CreateTime < #{endDate};
上面两个sql中用到的查询条件相同,所以我们提取相同查询条件
and p.productNo like '%${productNo}%' and p.productName like '%${productName}%' and o.istatus >= 0 and o.CreateTime >= #{startDate} and o.CreateTime < #{endDate}
在sql中使用查询条件
select * from product



