有一个字段输入查询内容的全称时查不到,领导问我%A%这个格式的模糊查询,如果查询的内容为A时,无法查询到,我郁闷了一把,经过查询,%在正则表达式中是匹配0个或多个字符。
请看在下的sql
<select id="searchFigureData" resultType="Map">
select
tt.*
from
(select
t.*, dft.name as typeName
from
(select
df.id, df.type, df.module, df.sub_type, df.card as cardName,
if(df.applicant='null', '', df.applicant) as applicant,
df.apply_date as applyDate, df.fig_num as figNum,
df.pro_name as pName, dt.name as subName,
if(df.p_id='null', '', df.p_id) as pId
from
dproject_figurenum df
left join
dproject_figurenum_type dt
on dt.id = df.sub_type
) as t
left join
dproject_figurenum_type dft
on
dft.id = t.type
) as tt
<where>
<if test="content != '' and content != null">
applicant like CONCAT("%", #{content}, "%")
OR typeName like CONCAT("%", #{content}, "%")
OR subName like CONCAT("%", #{content}, "%")
OR pName like CONCAT("%", #{content}, "%")
OR pId like CONCAT("%", #{content}, "%")
OR figNum like CONCAT("%", #{content}, "%")
OR applyDate like CONCAT("%", #{content}, "%")
OR cardName like CONCAT("%", #{content}, "%")
OR module like CONCAT("%", #{content}, "%")
</if>
</where>
order by
tt.figNum DESC, tt.applyDate DESC
</select>
但是发现少写了一个查询字段,最后添上了。。。完美。。。。