When using mybatis write SQL statements, frequently encountered conditions to the value of the parameter to query different fields, to make a summary here:
<where>
<!-- 判断条件参数是否为空 -->
<if test="orgId != 'null' and orgId != ''">
and user.org_id = #{orgId}
</if>
<!-- 判断条件参数是否为某值 -->
<if test="searchCon == 'cn'">
and opxuser.name like CONCAT(#{searchCon},'%')
</if>
</where>
As used herein,
more elegant than adding 1 = 1 is written in the back where.