Java 将in子句中的字符串列表与JDBI一起使用

Java 将in子句中的字符串列表与JDBI一起使用,java,postgresql,dropwizard,jdbi,Java,Postgresql,Dropwizard,Jdbi,我正在为一个项目使用JDBI/Dropwizard,并希望运行一些简单的查询。我有这样一个问题: private static final String GET_STUFF=“SELECT*FROM myTable WHERE state IN(:desiredState)” 我在方法中绑定变量,如下所示: @Mapper(MyType.class) @SqlQuery(GET_STUFF) public MyType getStuff(@Bind(desiredState) List<S

我正在为一个项目使用JDBI/Dropwizard,并希望运行一些简单的查询。我有这样一个问题:

private static final String GET_STUFF=“SELECT*FROM myTable WHERE state IN(:desiredState)”

我在方法中绑定变量,如下所示:

@Mapper(MyType.class)
@SqlQuery(GET_STUFF)
public MyType getStuff(@Bind(desiredState) List<String> states);

我以字符串类型的
ArrayList
传递
states
,所以我有点搞不清楚这里发生了什么。有人知道使用JDBI在
中执行
的正确方法吗?

使用注释
@BindIn
而不是
@Bind
。 另外,
:desiredState
应该写成
以下是对我有用的东西(
JDBI 3.1.1
):


在JDBI 3中,所需注释可能被更改为
@BindList
org.skife.jdbi.v2.exceptions.UnableToCreateStatementException: 
Exception while binding 'desiredState'....
Caused by: org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of java.util.ArrayList. Use setObject() with an explicit Types value to specify the type to use.
import org.jdbi.v3.sqlobject.customizer.BindList;
import org.jdbi.v3.sqlobject.statement.SqlUpdate;

public interface JdbiRoom {
    @SqlUpdate("update Room set available = 0 where id in (<roomIds>)")
    int markRoomsAsUnavailable(@BindList("roomIds") List<Long> roomIds);
}
markRoomsAsUnavailable(roomIds) ::= <<
    update rooms set available = 0 where id in (<roomIds>)
>>
@SqlQuery("SELECT ... WHERE xxx in (<uids>)")

@BindIn(value = "uids", onEmpty = BindIn.EmptyHandling.VOID) List<String> ids
@UseStringTemplate3StatementLocator