JDBI - Convenient SQL for Java
In order to write in queries like the one below in JDBI. Writing queries with in statement could be a very popular use case.
select id, name from books where id in (1,2,3,4,5);
Writing in Queries in JDBI
Use the below annotation
@UseStringTemplate3StatementLocator
Mvn dependency to be added :
<dependency>
<groupId>org.antlr</groupId>
<artifactId>stringtemplate</artifactId>
<version>3.2.1</version>
</dependency>
Code would look something like this:
@UseStringTemplate3StatementLocator
public interface BookDao {
@SqlQuery("select id,name from books where id in (<id>)")
@Mapper(BookMapper.class)
List<Ledger> findBooks(@BindIn("id") List<Integer> id);
}
Comments
Post a Comment