MyBatis-------使用IN语句

一、使用foreach

        注意点:Java的List需要传 List<Long>

<select id="get" resultType="..">

        SELECT * from t_article
        WHERE id in
        <foreach collection="list" item="articleId" open="(" close=")" separator=",">
            #{articleId}
        </foreach>

</select>

        解析后效果:

SELECT * from t_article WHERE id in ( 21 , 22 ,23 )

       删除实例与插入实例大同小异。比如

delete from t_tag where id in ( 58 , 59 ) 

二、字符串情况

        如果希望达到的效果是  in ( '2019-2020-1' , '2019-2020-2'  '2020-2021-1' )

        集合需要传 List<String>

<!-- in ("2019-2020-1" , "2020-2020-1" )-->
<foreach collection="list" item="termCode" open="("  close=")" separator=",">
    #{termCode}
</foreach>

更多MyBatis使用经验

         MyBaits操作经验目录贴

posted @ 2022-07-17 12:15  小大宇  阅读(235)  评论(0编辑  收藏  举报