Mybatis @Select注解,使用in传入ids数组作为参数 &&当参数为空则不添加该参数的判断

    @Select({
            "<script>",
                "select",
                "id, name, user_id",
                "from label",
                "where id in",
                    "<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
                    "#{id}",
                    "</foreach>",
            "</script>"
    })
    List<LabelDTO> getLabelsByIds(@Param("ids") List<Long> ids);

注意:

1,@Select后面的括号包含大括号

2, 使用<script>标签

3,@Select后面大括号中的代码,每行后面使用逗号结束

2、当参数为空则不添加该参数的判断

@Select({"<script>",
    "SELECT * FROM tbl_order",
    "WHERE 1=1",
    "<when test='title!=null'>",
    "AND mydate = #{mydate}",
    "</when>",
    "</script>"})
原文地址:https://www.cnblogs.com/dancser/p/13877697.html