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>"})

 


免責聲明!

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



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