xml文件里面内容
//这是普通的查询语句
<select id="getUserDirectCode" resultType="Map">
select a.country,a.province,a.city,a.district from area a where a.area_code = #{area_code} order by a.area_code limit 1
</select>
//但是这样有问题,如果为空呢?就像下面这个语句,有四个条件,如果为空,直接拼接就会有问题,就按下面这样写,进行判断,有值则进行拼接,就ok了。
<select id="query" parameterType="java.util.Map" resultType="java.util.Map">
SELECT area_code FROM dict_area WHERE
<if test="cond1 != null and cond1 != ''">
cond1 = #{cond1}
</if>
<if test="cond2 !=null and cond2 != ''">
and cond2 = #{cond2}
</if>
<if test="cond3 !=null and cond3 != ''">
and cond3 = #{cond3}
</if>
<if test="cond4 !=null and cond4 != ''">
and cond4 = #{cond4}
</if>
<if test="sourceid !=null ">
and 3rd_part = #{sourceid} limit 1
</if>
</select>