How to do in-query in jDBI?

后端 未结 4 631
轮回少年
轮回少年 2020-12-05 17:11

How can I execute somethings like this in jDBI ?

@SqlQuery(\"select id from foo where name in \")
List getIds(@Bind(         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 17:53

    This should work:

    @SqlQuery("select id from foo where name in ()")
    List getIds(@BindIn("nameList") List nameList);
    

    Don't forget to annotate class containing this method with:

    @UseStringTemplate3StatementLocator
    

    annotation (beacuse under the hood JDBI uses Apache StringTemplate to do such substitutions). Also note that with this annotation, you cannot use '<' character in your SQL queries without escaping (beacause it is a special symbol used by StringTemplate).

提交回复
热议问题