XStream

下载地址:[url]http://xstream.codehaus.org/download.html[/url]


取别名:
package bean;

import java.util.Date;
import com.thoughtworks.xstream.annotations.XStreamAlias;
@XStreamAlias("Query")
public class Query {
private Query(){}
private static Query query = new Query();

@XStreamAlias("CmdType")
private String CmdType;

@XStreamAlias("SN")
private int sn;

@XStreamAlias("DeviceID")
private String DeviceID;

@XStreamAlias("StartTime")
private Date StartTime;

@XStreamAlias("EndTime")
private Date EndTime;

@XStreamAlias("FilePath")
private String filePath;

@XStreamAlias("Address")
private String address;

@XStreamAlias("Secrecy")
private int secrecy;
@XStreamAlias("Type")
private String type;

@XStreamAlias("RecorderID")
private String recorderID;

public static Query getInstance(){
query.setCmdType("RecordInfo");
query.setSn(17430);
query.setStartTime(new Date());
query.setEndTime(new Date());
query.setFilePath("64010000002100000001");
query.setAddress("Address");
query.setSecrecy(0);
query.setType("time");
query.setRecorderID("64010000003000000001");
return query;
}

public String getCmdType() {
return CmdType;
}

public void setCmdType(String cmdType) {
CmdType = cmdType;
}

public int getSn() {
return sn;
}

public void setSn(int sn) {
this.sn = sn;
}

public String getDeviceID() {
return DeviceID;
}

public void setDeviceID(String deviceID) {
DeviceID = deviceID;
}

public Date getStartTime() {
return StartTime;
}

public void setStartTime(Date startTime) {
StartTime = startTime;
}

public Date getEndTime() {
return EndTime;
}

public void setEndTime(Date endTime) {
EndTime = endTime;
}

public String getFilePath() {
return filePath;
}

public void setFilePath(String filePath) {
this.filePath = filePath;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getRecorderID() {
return recorderID;
}

public void setRecorderID(String recorderID) {
this.recorderID = recorderID;
}

public int getSecrecy() {
return secrecy;
}
public void setSecrecy(int secrecy) {
this.secrecy = secrecy;
}
}




import com.thoughtworks.xstream.XStream;

import bean.Query;


public class VieoFile {


private static String xml = "<Query> <CmdType>RecordInfo</CmdType><SN>17430</SN><StartTime>2012-09-12 16:30:26.608 CST</StartTime><EndTime>2012-09-12 16:30:26.608 CST</EndTime><FilePath>64010000002100000001</FilePath><Address>Address</Address> <Secrecy>0</Secrecy><Type>time</Type> <RecorderID>64010000003000000001</RecorderID></Query>";

public static void main(String[] args) {


/* Query q = Query.getInstance();
XStream stream = new XStream();
stream.autodetectAnnotations(true);
System.out.println(stream.toXML(q));
*/
XStream stream = new XStream();
//指定使用别名
stream.autodetectAnnotations(true);
//Query与Query类上的别名一致
stream.alias("Query", Query.class);
Query query = (Query)stream.fromXML(xml);


System.out.println(query.getCmdType());
}


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值