使用if标签进行查询
1
2
3
4
5
6
7
8
9
10
11
12
13
|
SELECT orderNo, adname, orderstatus FROM order_A where <if test= "order!=null" > order =#{ order } </if> <if test= "title!=null" > and title=#{title} </if> |
需要注意的是:如果第一个if的order为null的话 第二值title也为null的话运行会报错,就算第一个if等于null 那么查询语句变成 where and sql" id="highlighter_26932">
SELECT
orderNo,
adname,
orderstatus
FROM
order_A
<
where
>
<if test=
"order!=null"
>
order
=#{
order
}
</if>
<if test=
"order!=null"
>
and
title=#{title}
</if>
</
where
>