1.要实现选择不同的条件组合查询,后台的sql没想明白怎么哢
select * from table where 1=1
后面根据有填写的条件添加
and 条件1
and 条件2
、、、、、、
同意1楼,不过在具体实现 的时候 要加判断(假如全为空where 1=1 永远成立就成了全部查询这里需要注意)
给你个参考的你就明白了:
select
*
from tbl_su_red_packet p
LEFT JOIN tbl_su_red_type t ON p.red_type=t.id
where 1=1
<if test="sequenceNumber!=null and sequenceNumber!='' ">
AND p.sequence_number=#{sequenceNumber}
</if>
<if test="mobile!=null and mobile!='' ">
AND p.mobile=#{mobile}
</if>
<if test="redType!=null and redType!=0">
AND t.condition=#{redType}
</if>
<if test="usedType!=null and usedType==2"><!-- status=2,已使用的红包 -->
AND p.status=2
</if>
<if test="status!=null">
AND p.status=#{status}
</if>
<if test="startTime!=null and endTime!=null">
AND p.create_date_time <![CDATA[ >= ]]> #{startTime,jdbcType=TIMESTAMP}
and p.create_date_time <![CDATA[ <= ]]> #{endTime,jdbcType=TIMESTAMP}
</if>