【发布时间】:2015-09-02 14:25:59
【问题描述】:
MySql 查询:
select 'customers' tableName , customers.* from customers
这是序列化函数:
List<?> received = exchange.getIn().getBody(List.class);
FileOutputStream fich = new FileOutputStream("xmlop.xml");
XMLEncoder x = new XMLEncoder(new BufferedOutputStream(fich));
x.writeObject(received);
x.flush();
x.close();
结果
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.8.0_45" class="java.beans.XMLDecoder">
<object class="java.util.ArrayList">
<void method="add">
<object class="org.springframework.util.LinkedCaseInsensitiveMap">
<void method="put">
<string>tableName</string>
<string>customers</string>
</void>
<void method="put">
<string>id</string>
<int>1</int>
</void>
<void method="put">
<string>firstname</string>
<string>zied</string>
</void>
<void method="put">
<string>lastname</string>
<string>saffar</string>
</void>
</object>
</void>
<void method="add">
<object class="org.springframework.util.LinkedCaseInsensitiveMap">
<void method="put">
<string>tableName</string>
<string>customers</string>
</void>
<void method="put">
<string>id</string>
<int>2</int>
</void>
<void method="put">
<string>firstname</string>
<string>mohamed</string>
</void>
<void method="put">
<string>lastname</string>
<string>houidi</string>
</void>
</object>
</void>
</object>
</java>
我该怎么做才能有这样的东西:
<customer>
<id>1</id>
<firstname>zied</firstname>
<lastname>saffar</lastname>
</customer>
<customer>
<id>1</id>
<firstname>zied</firstname>
<lastname>saffar</lastname>
</customer>
=> 名称字段作为标签
【问题讨论】:
标签: java xml xml-serialization