Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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
Spring batch 要在子句中支持的SqlPagingQueryProviderFactoryBean_Spring Batch - Fatal编程技术网

Spring batch 要在子句中支持的SqlPagingQueryProviderFactoryBean

Spring batch 要在子句中支持的SqlPagingQueryProviderFactoryBean,spring-batch,Spring Batch,我想为SqlPagingQueryProviderFactoryBean编写一个SQL。我将传递IN子句的参数。当我将其作为参数(?)传递时,我没有得到结果。但是当我硬编码这些值时,我得到了正确的结果 请指导我。由于sql注入安全策略的原因,您不能使用单个占位符并将其替换为数组,但是sqlPagingQueryProvider properties selectclause、fromClause和whereCLause的getter/setter是String而不是preparedStateme

我想为SqlPagingQueryProviderFactoryBean编写一个SQL。我将传递IN子句的参数。当我将其作为参数(?)传递时,我没有得到结果。但是当我硬编码这些值时,我得到了正确的结果


请指导我。

由于sql注入安全策略的原因,您不能使用单个占位符并将其替换为数组,但是sqlPagingQueryProvider properties selectclause、fromClause和whereCLause的getter/setter是String而不是preparedStatement。PreparedStatement将在后期构造方法中由spring batch稍后构造。因此,您可以将where子句作为带值的字符串发送(Prepared),并将其作为参数传递给作业。因此,您的代码可能是这种类型的

String topics = { "topic1", "topic2", "topic3", "topic4"};

StringBuilder str = new StringBuilder("('");

for (String topic : topics) {
    str.append(topic + "','");
}
str.setLength(str.length() - 2);
str.append("')");


final JobParameters jobParameters = new JobParametersBuilder()
                .addLong("time", System.nanoTime())
                .addString("inputsTopics", str.toString())
                .toJobParameters();
您的PagingReaderbean如下所示,并确保将范围设置为步骤

<bean id="sqlPagingReader" class="<your extended prging prvder>.KPPageingProvider" scope="step" >
        <property name="dataSource" ref="dataSource" />
        <property name="selectClause" value="u.topic,cu.first_name ,cu.last_name, cu.email" />
        <property name="fromClause" value="ACTIVE_USER_VIEWS_BY_TOPIC u inner join cl_user cu on u.user_id=cu.id" />
        <property name="whereClause" value="u.topic in #{jobParameters['inputsTopics']}" ></property>
</bean>


example和example在sqlPagingQueryProviderBean的my from子句中,我有以下sql:选择u.topic,cu.first\u name,cu.last\u name,cu.email from ACTIVE\u USER\u VIEWS\u BY\u topic u internal join cl\u USER cu on u.USER\u id=cu.id,其中u.topic in(?)和我的paramaValue中,我将参数作为发送,paramString的值为(‘主题1’、‘主题2’)