概述
import java.io.Serializable;
import com.thoughtworks.xstream.annotations.XStreamAlias;
//@XStreamAlias("newstype")
public class News implements Serializable{private String id;
private String title;
private String body;
private String commentCount;
private String pubDate;
private String url;
private String author;
private String authorid;
private New newstype;
//里面只有单一的属性
public class New implements Serializable {
private String type;
private String authoruid2;
private String eventurl;
private String attachment;
//将对象和集合进行注解
package com.example.vo;
import java.io.Serializable;
import java.util.List;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
//注解对象
@XStreamAlias("newslist")
public class NewData implements Serializable{
//注解集合
@XStreamImplicit(itemFieldName="news")
private List<News> news;
public List<News> getNews() {
return news;
}
public void setNews(List<News> news) {
this.news = news;
}
}
package com.example.vo;
import java.io.Serializable;
import com.thoughtworks.xstream.annotations.XStreamAlias;
注解最外层的标签,,对象
@XStreamAlias("oschina")
public class NewsObject implements Serializable{
private String catalog;
private String newsCount;
private String pagesize;
private NewData newslist;
public String getCatalog() {
return catalog;
}
public void setCatalog(String catalog) {
this.catalog = catalog;
}
public String getNewsCount() {
return newsCount;
}
public void setNewsCount(String newsCount) {
this.newsCount = newsCount;
}
public String getPagesize() {
return pagesize;
}
public void setPagesize(String pagesize) {
this.pagesize = pagesize;
}
public NewData getNewslist() {
return newslist;
}
public void setNewslist(NewData newslist) {
this.newslist = newslist;
}
}
最后
以上就是顺心太阳为你收集整理的Xml文件如何封装,,如何注解的全部内容,希望文章能够帮你解决Xml文件如何封装,,如何注解所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复