我正在使用dropwizard jdbi和数据库postgresql:
@Mapper(StudentMapper.class)
@SqlQuery("select user_registration.username,user_registration.user_email,user_registration.picname,"
+"student_specific.subject_name from user_registration inner join "
+"student_specific on user_registration.user_email=student_specific"
+".student_email where (subject_name @> ARRAY[':subject'])"
)
StudentDetails searchStudents(@Bind("subject")String subject);
我的问题是当我给ARRAY ['maths']它会给出结果,但是当我给ARRAY [':subject']时它返回null,似乎它不是绑定主题并且将':subject'作为值请帮我解决如何通过:主题
答案 0 :(得分:0)
您需要使用 @ UseStringTemplate3StatementLocator ,此注释允许我们在查询中使用<arg>
语法。
例如:
@UseStringTemplate3StatementLocator
public interface StudentDao {
@Mapper(StudentMapper.class)
@SqlQuery("select user_registration.username,user_registration.user_email,user_registration.picname,"
+"student_specific.subject_name from user_registration inner join "
+"student_specific on user_registration.user_email=student_specific"
+".student_email where (subject_name @> ARRAY[<subject>])"
)
StudentDetails searchStudents(@BindIn("subject") List<String> subject);
}
您可能需要添加显式类型转换。
ARRAY[<subject>]::text[]
并转义::
ARRAY[<subject>]\\:\\:text[]
要使用StringTemplate,请将此依赖项添加到pom.xml
<dependency>
<groupId>org.antlr</groupId>
<artifactId>stringtemplate</artifactId>
<version>3.2.1</version>
</dependency>