<?xml version="1.0"?> <Results xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Code>0</Code> <Message></Message> <Data xsi:type="BlcInOutStoreResponse"> <InOutStoreHead> <oid>1</oid> <sasStockPreentNo>1</sasStockPreentNo> <sasStockNo>1</sasStockNo> <chgTmsCnt>1</chgTmsCnt> </InOutStoreHead> <InOutStoreList> <headOid>1</headOid> <sasStockSeqno>1</sasStockSeqno> <chgTmsCnt>1</chgTmsCnt> <gdsMtno>1</gdsMtno> </InOutStoreList> <InOutStorePassPortList> <PassportNo>1</PassportNo> </InOutStorePassPortList> </Data> </Results> 创建相对应的java类
时间: 2023-07-09 18:08:17 浏览: 170
根据上面的XML文件可以创建以下Java类:
```java
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Results")
public class BlcInOutStoreResponse {
@XmlElement(name = "InOutStoreHead")
private InOutStoreHead inOutStoreHead;
@XmlElement(name = "InOutStoreList")
private InOutStoreList inOutStoreList;
@XmlElement(name = "InOutStorePassPortList")
private InOutStorePassPortList inOutStorePassPortList;
// getters and setters
}
@XmlAccessorType(XmlAccessType.FIELD)
class InOutStoreHead {
@XmlElement(name = "oid")
private int oid;
@XmlElement(name = "sasStockPreentNo")
private int sasStockPreentNo;
@XmlElement(name = "sasStockNo")
private int sasStockNo;
@XmlElement(name = "chgTmsCnt")
private int chgTmsCnt;
// getters and setters
}
@XmlAccessorType(XmlAccessType.FIELD)
class InOutStoreList {
@XmlElement(name = "headOid")
private int headOid;
@XmlElement(name = "sasStockSeqno")
private int sasStockSeqno;
@XmlElement(name = "chgTmsCnt")
private int chgTmsCnt;
@XmlElement(name = "gdsMtno")
private int gdsMtno;
// getters and setters
}
@XmlAccessorType(XmlAccessType.FIELD)
class InOutStorePassPortList {
@XmlElement(name = "PassportNo")
private int passportNo;
// getters and setters
}
```
这里使用了JAXB(Java Architecture for XML Binding)来进行XML和Java类之间的映射。注意要添加相应的依赖,比如在Maven项目中可以添加以下依赖:
```xml
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.2</version>
</dependency>
```
阅读全文