是否有可能具有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