1. 程式人生 > >sql xml中 in 的用法

sql xml中 in 的用法

ive 代碼 list ram 接口 tab table div -s

在xml中,動態傳參去數據庫查詢,下面是in的示例。

比如有條sql

SELECT *
FROM corp_tax c WHERE c.id
in (387419,387423) AND c.corp_year=2018 AND c.corp_month =6  and c.park_id =1 LIMIT 5

這條sql,如果要動態傳參,xml的代碼如下

<select id="tableFive" resultMap="twoToNine">

      SELECT c.corp_name,c.month_tax_data as tax_data,c.month_fiscal_ret as fiscal_ret
      FROM corp_tax c WHERE c.id
      in
      
<foreach collection="list" separator="," item="item" open="(" close=")"> #{item} </foreach> AND c.corp_year=#{year} AND c.corp_month =#{month} and c.park_id =#{parkId} LIMIT 5 </select>

mapper的接口為:

List<TwoToNine> tableFive(@Param("year") Integer year, @Param("month") Integer month, @Param("parkId") Integer parkId, @Param("list") List<
Integer> list);

上面mapper中的參數要用@param綁定,要不然傳入多個參數會報錯。

sql xml中 in 的用法