CamelConfig.java
@Component
public class CamelConfig extends RouteBuilder {
@Override
public void configure() throws Exception {
try {
CamelContext context = new DefaultCamelContext();
ConverterRoute route = new ConverterRoute();
route.addRoutesToCamelContext(context);
context.start();
Thread.sleep(5000);
context.stop();
} catch (Exception exe) {
exe.printStackTrace();
}
}
}
ConverterRoute.java
public class ConverterRoute implements RoutesBuilder {
private static final String SOURCE_INPUT_PATH = "file://inbox?fileName=Source.txt";
private static final String SOURCE_OUTPUT_PATH = "file://outbox?fileName=file.xml";
public void addRoutesToCamelContext(CamelContext context) throws Exception {
context.addRoutes(new RouteBuilder() {
public void configure() {
try {
DataFormat bindyFixed = new BindyCsvDataFormat(Test.class);
from(SOURCE_INPUT_PATH).
unmarshal(bindyFixed).
marshal().
xstream().
to(SOURCE_OUTPUT_PATH).log("Finished Transformation").end();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
来源.txt
55158|11901|2346
55158|11101|3454
Test.java
@CsvRecord(separator = "\\|",skipField = true,name = "Test")
public class Test {
@DataField(pos = 1,name = "ALT_NUM")
private BigDecimal ALT_NUM;
@DataField(pos = 2,name = "PRTNUM")
private BigDecimal PRTNUM;
@DataField(pos = 3,name = "UOMCOD")
private Integer UOMCOD;
}
我能够生成包含单个文件中所有字段的 xml 文件。我想要单个 xml 文件中的单个记录。任何人都可以帮助我。输出文件根元素中的标签名称也生成类的包名称。
POPMUISE
相关分类