Setting a parameter as a list for an IN expression

前端 未结 9 2502
北荒
北荒 2020-11-30 07:14

Whenever I try to set a list as a parameter for use in an IN expression I get an Illegal argument exception. Various posts on the internet seem to indicate that this is poss

9条回答
  •  隐瞒了意图╮
    2020-11-30 08:17

    You can also try this syntax.

    static public String generateCollection(List list){
        if(list == null || list.isEmpty())
            return "()";
        String result = "( ";
        for(Iterator it = list.iterator();it.hasNext();){
            Object ob = it.next();
            result += ob.toString();
            if(it.hasNext())
                result += " , ";
        }
        result += " )";
        return result;
    }
    

    And put into query, "Select * from Class where field in " + Class.generateCollection(list);

提交回复
热议问题