mybatis 条件查询
(1)没有if,else.用when/otherwise做条件选择。
(2)等于判断用双引号,如 orgLevel == "2" 做条件,单引号不起作用。
<choose>
<when test='orgLevel != null and orgLevel != "" and orgLevel == "2"'>
and oi.org_level = #{orgLevel}
<if test="cityOrgCode != null and cityOrgCode != ''">and hp.org_code = #{cityOrgCode}</if>
</when>
<when test='orgLevel != null and orgLevel != "" and orgLevel == "3"'>
and oi.org_level = #{orgLevel}
<if test="cityOrgCode != null and cityOrgCode != ''">and <![CDATA[ find_in_set(#{cityOrgCode}, oi.ancestors) <> 0 ]]></if>
</when>
<otherwise>
<if test="orgLevel != null and orgLevel != ''">and oi.org_level = #{orgLevel}</if>
</otherwise>
</choose>
<if test="countryOrgCode != null and countryOrgCode != ''"> and hp.org_code = #{countryOrgCode}</if>