mybtis in 查詢傳入參數為list


 

1 如果傳入參數只有一個且類型是List, 則在使用時,collection屬性要必須指定為 list

例:

mapper.java

List<TYzglKhjls> selectWxlsByZyryBh(List<String> yxlsbhList);

mapper.xml

<select id="selectWxlsByZyryBh" resultMap="BaseResultMap">
       select c_bh, c_zyry_bh, c_zyry_dh, c_lsxm, c_zjhm, c_lxdh, n_sfyx, c_ssdw
        from {db.t_yzgl_khjls}
        where n_sfyx = 1 and c_bh not in
            <foreach collection="list"  item="item"  open="(" separator="," close=")">  
                     #{item}  
            </foreach>  
 </select>

 

 

 2,如果傳入參數使用了@Param(value="value"),collection的屬性必須為"value"值

例:

mapper.java

List<TYzglKhjls> selectWxlsByZyryBh(@Param("zyrybh")String zyrybh, @Param("yxlsbhList")List<String> yxlsbhList);

mapper.xml

<select id="selectWxlsByZyryBh" resultMap="BaseResultMap">
       select c_bh, c_zyry_bh, c_zyry_dh, c_lsxm, c_zjhm, c_lxdh, n_sfyx, c_ssdw
        from {db.t_yzgl_khjls}
        where c_zyry_bh = #{zyrybh} and n_sfyx = 1
               <if test="yxlsbhList != null and yxlsbhList.size() &gt; 0">
                and c_bh  in
                <foreach collection="yxlsbhList"  item="item"  open="(" separator="," close=")">  
                         #{item}  
                </foreach>  
            </if> 
    </select>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM