myabtis中使用not in與 in的寫法

首先聲明我不是很喜歡用foreach,所以我的代碼中很少出現foreach。不廢話了,上代碼:

 in的用法:

我的id是Long類型的

service方法,有一個Long的集合:

public List<RbacMenu> listByPackageId(List<Long> ids, String systemCode) {
    Map<String, Object> map = new HashMap<String, Object>();
    if(ids.size()!=0) {
        StringBuilder sbd = new StringBuilder();
        for(Long cateIds:ids){
            sbd.append(cateIds+",");
        }
        String idStr = sbd.toString();
        idStr = idStr.substring(0,idStr.length()-1);
        map.put("ids", idStr);
    }

實體類.xml

select * from xxx where 

<if test="ids != null"> FIND_IN_SET(id,#{ids})   </if>

not in的用法

service方法,有一個Long的集合:

public List<RbacMenu> listByPackageId(List<Long> ids, String systemCode) {
    Map<String, Object> map = new HashMap<String, Object>();
    if(ids.size()!=0) {
        StringBuilder sbd = new StringBuilder();
        for(Long cateIds:ids){
            sbd.append(cateIds+",");
        }
        String idStr = sbd.toString();
        idStr = idStr.substring(0,idStr.length()-1);
        map.put("notids", idStr);
    }

實體類.xml

select * from xxx where 

<if test="notids != null"> NOT FIND_IN_SET(id,#{notids})   </if>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章