当AND和OR同时使用时,要把OR的条件使用小括号括起来
例如下边这个例子,在第一个if标签中同时使用了AND和OR,
想要实现同一个搜索框搜索两个字段,如果不加括号则会搜索内容出错
<select id="selectAll" parameterType="com.jh.store.entity.criteris.GoodsCriteria" resultType="com.jh.store.entity.domain.GoodsInfor">
select
t_bus_goods.id,
goods_name,orig_price,
t_ent_store.store_name,
t_bus_goods.good_type_name,
consum_start_date,
pic_url,
max_count,
share_num,
start_date,
during,
t_bus_goods.end_date,
is_show,
share_status,
sex_limit,
male_count,
female_count,
time_end_logic,
t_bus_goods.description
from
t_bus_goods,t_ent_store
WHERE
t_bus_goods.store_id=t_ent_store.id
<if test="null!= name">
and (goods_name like "%"#{name}"%" or store_name like "%"#{name}"%")
</if>
<if test="-3 != is_check">
and share_status=#{is_check}
</if>
<if test="null!=onetime">
and t_bus_goods.consum_start_date <![CDATA[ >= ]]> #{onetime}
</if>
<if test="null!=twotime">
and t_bus_goods.consum_start_date <![CDATA[ <= ]]> #{twotime}
</if>
<if test="null!=onlytime">
and t_bus_goods.consum_start_date <![CDATA[ >= ]]> #{onlytime}
and t_bus_goods.consum_start_date <![CDATA[ < ]]> #{onlytime2}
</if>
ORDER BY consum_start_date DESC
</select>