當mybatis有多個參數時,mapper.java文件即dao層必須寫上@Param註解
List<AddressBean> listAddressByDate(@Param("startDate")String startDate, @Param("endDate")String endDate);
然後在xml文件裏用where if判斷是否爲空,注意if的test判斷裏不要加#{ }
<select id="listAddressByDate" resultType="cn.zwkj.beans.AddressBean" parameterType="String">
select biaozhunmingcheng,hanyuduyin,dzzzcode,dengjishijian,id from t_placecommon
<where>
<if test="startDate!=null and startDate != '' ">
and to_char(dengjishijian,'yyyy-MM-dd') <![CDATA[>=]]> #{startDate}
</if>
<if test="endDate!=null and endDate != '' ">
and to_char(dengjishijian,'yyyy-MM-dd') <![CDATA[<=]]> #{endDate}
</if>
</where>
</select>