1

我的问题是我的平面文件中有两个不同的位置,带有“|” 分隔的字符串。位置 2 和 3 参见说明。我想生成将两个描述附加到一个描述的 xml,并返回一个包含两个描述的 DESC 标记。

输入源:

UN|2.1  |AEROSOLS

预期输出:

<TEST>
<STATE>UN</STATE>
<DESC>2.1 AEROSOLS</DESC>
</TEST>

我得到的输出:

    <TEST>
    <STATE>UN</STATE>
    <DESC_ONE>2.1 AEROSOLS</DESC_ONE>
    <DESC_TWO>AEROSOLS<DESC_TWO>
    </TEST>

测试.java

@Data
public class TEST {


    @DataField(pos = 1, name = "STATE", required = true)
    private String STATE;

    @DataField(pos = 2, name = "DESC",required = true)
    private String DESC_ONE;

    @DataField(pos = 3, name = "DESC",required = true)
    private String DESC_TWO;


}

转换器.java

                            from(SOURCE_INPUT_PATH).
                            log("Received input from file and body is ${body}").
                            unmarshal(bindyBeanConfig.bindyCsvDataFormat3280()).
                            process(new Processor()  {
                                @Override
                                public void process(Exchange exchange) throws Exception {

                                    TEST test = exchange.getIn().getBody(TEST.class);
                                    DESC_ONE descOne = test.getTEST();
                                    DESC_TWO descTwo = descOne.getDESC_ONE();

                                    String description = descOne.getDESC_ONE() + descTwo.getDESC_TWO();

                                    descOne.set_DESCONE(description);

                                    exchange.getIn().setBody(descTwo);

                                }
                            }).
4

1 回答 1

1

我不太了解apache-camel,但是你可以有另一个DataFieldinTESTDESC,你可以设置DESC而不是DESC_ONEin Converter.java,在调用之前exchange.getIn().setBody(descTwo);你应该设置DESC_ONEDESC_TWOto null

于 2020-01-03T14:53:57.833 回答