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

发布了273 篇原创文章 · 获赞 77 · 访问量 49万+

猜你喜欢

转载自blog.csdn.net/spt_dream/article/details/104928254
今日推荐