當mybatis有多個參數時並增加判斷的寫法

當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>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章