Spring批处理使用> =和<在Where子句中

时间:2017-05-24 22:14:03

标签: java spring-batch spring-jdbc spring-batch-admin

尝试使用Spring Batch来读取仅在昨天创建的数据。下面是我尝试使用的bean,使用JdbcPagingItemReader& SqlPagingQueryProviderFactoryBean。但是,查询未执行。

感谢您的帮助!

<bean id="customersPagingItemReader"
    class="org.springframework.batch.item.database.JdbcPagingItemReader"
    scope="step">
    <property name="dataSource" ref="dataSource" />
    <property name="queryProvider">
        <bean
            class="org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean">
            <property name="dataSource" ref="dataSource" />
            <property name="selectClause" value="SELECT CUST_ID, CREATED " />
            <property name="fromClause" value=" from CUSTOMERS" />
            <property name="whereClause" value=" where CREATED &gt;= trunc(SYSDATE-1) and CREATED &lt; trunc(SYSDATE)" />
        </bean>
    </property>
    <property name="pageSize" value="5" />
    <property name="fetchSize" value="5" />
    <property name="rowMapper">
        <bean class="com.yahoo.affiliationapi.api.CustomerRowMapper" />
    </property>
</bean>

2 个答案:

答案 0 :(得分:1)

我能够弄清楚这一点。当我查看作业步骤退出消息时说 - '必须指定sortKey'

我刚将以下属性添加到上面的代码&amp;它开始工作正常。

<property name="sortKey" value="CUST_ID" />

答案 1 :(得分:0)

您必须为queryProvider设置排序键。 您可以参考以下示例:

@Bean
public SqlPagingQueryProviderFactoryBean queryProvider() {
        SqlPagingQueryProviderFactoryBean provider = new SqlPagingQueryProviderFactoryBean();

        provider.setSelectClause("select id, name, credit");
        provider.setFromClause("from customer");
        provider.setWhereClause("where status=:status");
        provider.setSortKey("id");

        return provider;
}