场景
持久层:MyBatis
组合查询一组数据,字段有:String id,String name ,Integer status。
由于三个字段都可能为空,所以mapper文件中这样写的:
SELECT
re.id,
re.name,
re.status
FROM
tj_registration_type re
WHERE
1=1
<if test="id!='' and id!= null and id!='undefined'">
AND re.id= #{id}
</if>
<if test="status!='' and status!= null and status!='undefined'">
AND re.status= #{status}
</if>
<if test="name!='' and name!= null and name!='undefined'">
AND re.name= #{name}
</if>
AND
re.is_delete=0
status取值为0或1,当status字段传值时ÿ