使用mybatisplus中@Select写动态sql语句foreach总是失效,是什么原因导致的,有人知道吗?一直找不出原因,代码如下:


 @Select("<script>"+
            "select id,authname,permission,uri from auth where id in (select distinct auth_id from role_auth where role_id in " +
            "   <foreach item='item' index='index' collection='list' open='(' separator=',' close=')'>\n" +
            "       #{item}" +
            "   </foreach>" +
            ")" +
            "</script>")
    List<AuthEntity>  selectByRoleIds(@Param("list") List<Long> list);

然后这是报错
SQL: select id,authname,permission,uri from auth where id in (select distinct auth_id from role_auth where role_id in )

Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

看下你的list是不是空的