mybatis註解sql多條件查詢,並做條件判斷

@Select("<script> SELECT * from jf_gift" +
            "<where>"+
            "<if test='cityId != null'>and city_id = #{cityId}</if> "+
            " <if test='periodId != null'>and period_id = #{periodId}</if> "+
            " <if test='activityId != null'>and activity_id = #{activityId}</if> and is_deleted = 1 order by update_time desc" +
            "</where>"+
            "</script>")
    List<JFGift> findGiftList (@Param("cityId") Integer cityId,
                               @Param("periodId") Integer periodId,
                               @Param("activityId") Integer activityId);

參考 https://blog.csdn.net/qq_36537546/article/details/88577221

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