我有以下java代码:
public class SomeType{
private String firstName;
private java.util.Date dob;
private Long someID;
private Double firstAmount;
private Double secondAmount;
private java.util.Date beginDate;
private java.util.Date endDate;
// setters and getters
}
对于上面的代码,以下是xml代码,它正常工作。
<xs:complexType name = "SomeType">
<xs:sequence>
<xs:element name = "firstName" type = "xsd:String"/>
<xs:element name = "dob" type = "xsd:date"/>
<xs:element name = "someID" type = "xsd:long"/>
<xs:element name = "firstAmount" type = "xsd:double"/>
<xs:element name = "secondAmount" type = "xsd:double"/>
<xs:element name = "beginDate" type = "xsd:date"/>
<xs:element name = "endDate" type = "xsd:date"/>
</xs:sequence>
</xs:complexType>
现在我在java代码中添加了以下字段:
List<Object[]> records = new ArrayList<Object[]>();
我从数据库中选择4个值(列),即“firstAmount”,“secondAmount”,“beginDate”和“endDate”,query.list()返回List<Object[]>
(即元组有4列) 。我正在“记录”(字段)中存储所有数据(在类型转换和迭代对象[]列表之后)。考虑到我们必须将此Field传递给架构中的其他层,如何为此Field(List<Object[]
&gt;记录)编写xsd代码。
提前谢谢。
答案 0 :(得分:0)
据我了解,您需要更换这部分XSD
<xs:element name = "firstAmount" type = "xsd:double"/>
<xs:element name = "secondAmount" type = "xsd:double"/>
<xs:element name = "beginDate" type = "xsd:date"/>
<xs:element name = "endDate" type = "xsd:date"/>
具有如下的复杂类型
<xs:element name="records">
<xs:complexType>
<xs:sequence>
<xs:element name="field" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name = "firstAmount" type = "xsd:double"/>
<xs:element name = "secondAmount" type = "xsd:double"/>
<xs:element name = "beginDate" type = "xsd:date"/>
<xs:element name = "endDate" type = "xsd:date"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
答案 1 :(得分:0)
<xs:complexType name = "SomeType">
<xs:sequence>
<xs:element name = "firstName" type = "xsd:String"/>
<xs:element name = "dob" type = "xsd:date"/>
<xs:element name = "someID" type = "xsd:long"/>
<xs:element name = "firstAmount" type = "xsd:double"/>
<xs:element name = "secondAmount" type = "xsd:double"/>
<xs:element name = "beginDate" type = "xsd:date"/>
<xs:element name = "endDate" type = "xsd:date"/>
<xs:element name = "records" type = "recordsType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name = "recordsType">
<xs:sequence>
<xs:element name = "record" type = "recordType" minOccurs="0" maxOccurs="unbounded"/><!-- a list or 0 or any number of records -->
</xs:sequence>
</xs:complexType>
<xs:complexType name = "recordType">
<!-- write the internal structure of your record element -->
</xs:complexType>