4

我有以下路线从 postgresql 获取数据,但日期对象为空。它无法映射该值

我的路线如果跟随

<route id="instrumentqueryshortsell">
        <from uri="direct:restinstumentshortsell"/>
        <bean ref="inConverter" method="convert"/>
        <setBody>
            <simple>select instrumentId as instrument_Id ,amount,easytoborrow as easy_To_Borrow,hardtoborrow as hard_To_Borrow ,datetime as date from instrument_short_sell where instrumentId in (${body}) </simple>
        </setBody>
        <log message="Running following query ${body} " loggingLevel="DEBUG"/>
        <to uri="jdbc:dataSource?useHeadersAsParameters=true&amp;outputClass=<packagename?.InstrumentShortSell" />

    </route>

我的 Pojo 课看起来像

import java.time.LocalDateTime;

import org.joda.time.DateTime;


public class InstrumentShortSell {

    private String instrumentId;
    private long amount;
    private boolean easyToBorrow;
    private boolean hardToBorrow;
    private DateTime date;

    public DateTime getDate() {
        return date;
    }
    public void setDate(DateTime date) {
        this.date = date;
    }
    public String getInstrumentId() {
        return instrumentId;
    }
    public void setInstrumentId(String instrumentId) {
        this.instrumentId = instrumentId;
    }
    public long getAmount() {
        return amount;
    }
    public void setAmount(long amount) {
        this.amount = amount;
    }
    public boolean isEasyToBorrow() {
        return easyToBorrow;
    }
    public void setEasyToBorrow(boolean easyToBorrow) {
        this.easyToBorrow = easyToBorrow;
    }
    public boolean isHardToBorrow() {
        return hardToBorrow;
    }
    public void setHardToBorrow(boolean hardToBorrow) {
        this.hardToBorrow = hardToBorrow;
    }


}

SQL 模式是

CREATE TABLE instrument_short_sell (
    instrumentId serial ,
    amount INTEGER,
    easytoborrow boolean,
    hardtoborrow boolean,
    datetime timestamp with time zone
) ;

我无法映射 jodadatetime 并且每次它都为空。请帮我看看我们如何在骆驼 jdbc 中映射它

4

1 回答 1

2

您需要添加一个类型转换器,org.joda.time.DateTime以便 Camel 可以将行值转换为 joda time 的实例。Camel 并非开箱即用这些转换器。

另一种方法是java.lang.Object在 POJO 类中用作参数类型,并在 setter 中进行类型转换。

于 2017-12-24T10:11:36.663 回答