天天看點

Mybtis中foreach周遊數組和集合動态拼接sqlMybtis中foreach周遊數組和集合動态拼接sql

Mybtis中foreach周遊數組和集合動态拼接sql

<select id="test" parameterType="java.util.List"  resultMap="Student">  
             <!--    
                使用foreach周遊傳入的list_tests集合  
                collection:指定輸入的對象中集合的屬性  
                item:每次周遊的元素生成的對象  
                open:開始周遊時生成的串  
                close:結束周遊時生成的串  
                separator:周遊的兩個對象中需要生成的串  
             -->  
    select id,name from test_table where id in  
    <foreach collection="list_tests" index="index" item="item" open="(" separator="," close=")">  
        #{item}  
    </foreach>  
</select>