是否有可能具有jDBI查询的可选(空)参数?我试图获得在数据库查询中工作的可选参数。我正在使用dropwizard。可选jDBI参数
@SqlQuery("SELECT * \n" +
"FROM posts \n" +
"WHERE (:authorId IS NULL OR :authorId = author_id)")
public List<Post> findAll(@Bind("authorId") Optional<Long> authorId);
查询时AUTHORID传递工作,但给我当它是NULL这个错误:
org.postgresql.util.PSQLException: ERROR: could not determine data type of parameter $1
这是我从调用资源路线:
@GET
public ArrayList<Post> getPosts(@QueryParam("authorId") Long authorId)
{
return (ArrayList<Post>)postDao.findAll(Optional.fromNullable(authorId));
}
从我读过的内容来看,这是可以做到的,所以我猜测我错过了一些东西或者有明显的错误。任何帮助将不胜感激!
仅供参考 - 我也试过它没有番石榴可选的(这是由dropwizard支持) - 只需发送一个作为一个长为null的authorId。只要它不为空,这也是有效的。
您应该检查[jdbi社会](http://jdbi.org/community.html) – zloster 2014-11-07 19:08:59
感谢@zloster,我贴这个有作为。 – nckturner 2014-11-11 19:20:25