Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java MySQL查询jdbi中的动态绑定选择值_Java_Mysql_Dropwizard_Dynamicquery_Jdbi - Fatal编程技术网

Java MySQL查询jdbi中的动态绑定选择值

Java MySQL查询jdbi中的动态绑定选择值,java,mysql,dropwizard,dynamicquery,jdbi,Java,Mysql,Dropwizard,Dynamicquery,Jdbi,如何在Jbdi中编写动态SQL查询,就像在我的项目中一样,客户会询问一些详细信息,如名字、姓氏、手机等。所以我将把这些值读入字符串,我的想法是直接将其动态地附加到SQL查询中,就像 select first name,last name,mobile from customer 而另一个用户只询问名字,那么我的查询将改变如下 select first name from customer where customer Id=12345 我正在使用JDBI对Dropwizard应用程序中动态生

如何在Jbdi中编写动态SQL查询,就像在我的项目中一样,客户会询问一些详细信息,如
名字、姓氏、手机等。所以我将把这些值读入字符串,我的想法是直接将其动态地附加到SQL查询中,就像

select first name,last name,mobile from customer
而另一个用户只询问
名字
,那么我的查询将改变如下

select first name from customer where customer Id=12345

我正在使用JDBI对Dropwizard应用程序中动态生成的搜索条件字符串执行类似的操作

@UseStringTemplate3StatementLocator
public interface ThingieDao {
    @SqlQuery
    @MapResultAsBean
    Iterator<Thingie> search(@Define("criteria") String criteria);
}
@UseStringTemplate3StatementLocator
公共接口ThingieDao{
@SqlQuery
@MapResultAsBean
迭代器搜索(@Define(“条件”)字符串条件);
}
然后可以在SQL模板中使用定义的字符串“criteria”:

group ThingieDao;
search(criteria) ::= <<
  SELECT * FROM table_name WHERE <criteria>
>>
groupthingiedao;
搜索(条件):=>
您可以使用相同的技术在SQL中插入任何字符串,在您的案例中选择列名


接口中的变量名并不重要,重要的是@Define注释字符串。。假设Dropwizard没有添加任何神奇的东西,而且通常不会,我想使用普通JDBI也应该可以。有可能这样做吗?