学堂 学堂 学堂公众号手机端

当mybatis有多个参数时并增加判断的写法

lewis 1年前 (2024-04-21) 阅读数 14 #技术


当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>
版权声明

本文仅代表作者观点,不代表博信信息网立场。

热门